Ruport

~/rubytesting/TheRubyProgrammingLanguage/chapter8ReflectionandMetaprogramming$ cat -n ruport_example.rb 
     1  require 'ruport'
     2  
     3  table = Ruport::Data::Table.new(
     4     :column_names => [               "alu",      "nota"],
     5     :data         => [ 
     6                        ["Almeida Gonzalez",         4.5],
     7                        ["Hernandez Perez",          6.5],
     8                        ["Mendez Chavez",            4.5],
     9                        ["Rodriguez Luis",           9.5]
    10                      ]
    11  )
    12  
    13  puts table.to_text
    14  
    15  dubious = table.rows_with_nota(4.5)
    16  dubious.each do |cal|
    17    puts cal.to_csv
    18  end

~$ sudo gem install ruport
Password:
Fetching: fastercsv-1.5.4.gem (100%)
Fetching: color-1.4.1.gem (100%)
Fetching: hoe-2.12.3.gem (100%)
Fetching: transaction-simple-1.4.0.gem (100%)
WARNING: transaction-simple-1.4.0 has an invalid nil value for @cert_chain
Fetching: pdf-writer-1.1.8.gem (100%)
WARNING: pdf-writer-1.1.8 has an invalid nil value for @cert_chain
Fetching: ruport-1.6.3.gem (100%)
Successfully installed fastercsv-1.5.4
Successfully installed color-1.4.1
Successfully installed hoe-2.12.3
Successfully installed transaction-simple-1.4.0
Successfully installed pdf-writer-1.1.8
Successfully installed ruport-1.6.3
6 gems installed
Installing ri documentation for fastercsv-1.5.4...
Installing ri documentation for color-1.4.1...
Installing ri documentation for hoe-2.12.3...
Installing ri documentation for transaction-simple-1.4.0...
Installing ri documentation for pdf-writer-1.1.8...
Installing ri documentation for ruport-1.6.3...
Installing RDoc documentation for fastercsv-1.5.4...
Installing RDoc documentation for color-1.4.1...
Installing RDoc documentation for hoe-2.12.3...
Installing RDoc documentation for transaction-simple-1.4.0...
Installing RDoc documentation for pdf-writer-1.1.8...
Installing RDoc documentation for ruport-1.6.3...
Instale también ruport-util
sudo gem install ruport-util 
$ sudo gem install scruffy
$ sudo gem install gruff

~/rubytesting/TheRubyProgrammingLanguage/chapter8ReflectionandMetaprogramming$ gem query --local | grep rupo
ruport (1.6.3)

$ export RUBYOPT=rubygems
~/rubytesting/TheRubyProgrammingLanguage/chapter8ReflectionandMetaprogramming$ ruby ruport_example.rb 
+-------------------------+
|       alu        | nota |
+-------------------------+
| Almeida Gonzalez |  4.5 |
| Hernandez Perez  |  6.5 |
| Mendez Chavez    |  4.5 |
| Rodriguez Luis   |  9.5 |
+-------------------------+
Almeida Gonzalez,4.5
Mendez Chavez,4.5

~$ gem which ruport
/Library/Ruby/Gems/1.8/gems/ruport-1.6.3/lib/ruport.rb

vi /Library/Ruby/Gems/1.8/gems/ruport-1.6.3/lib/ruport/data/table.rb

868     def method_missing(id,*args,&block)
869      return as($1.to_sym,*args,&block) if id.to_s =~ /^to_(.*)/
870      return rows_with($1.to_sym => args[0]) if id.to_s =~ /^rows_with_(.*)/
871      super
872     end

Vemos que la llamada dubious = table.rows_with_nota(4.5) se convierte en la línea 870 en una llamada a rows_with(nota.to_sym => args[0])



Casiano Rodriguez León 2015-06-18