Class: KittyReport
- Inherits:
-
Object
- Object
- KittyReport
- Defined in:
- lib/copycats/reports/kitty.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#fmt_kai(kai) ⇒ Object
helpers.
-
#initialize(*args, **kwargs) ⇒ KittyReport
constructor
A new instance of KittyReport.
- #save(path) ⇒ Object
Constructor Details
#initialize(*args, **kwargs) ⇒ KittyReport
Returns a new instance of KittyReport.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/copycats/reports/kitty.rb', line 5 def initialize( *args, **kwargs ) if args.empty? # try keyword args @id = kwargs[:id] @kai = kwargs[:genes] ## todo/check: also incl. check for kai key - why? why not? else # try positional args ## for now alsways assume ActiveRecord - Kitty::Model kitty = args[0] @id = kitty.id @kai = fmt_kai( kitty.genes_kai ) ## pretty print in groups of four (4) end end |
Instance Method Details
#build ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/copycats/reports/kitty.rb', line 18 def build buf = "# Kitty \##{@id}\n\n" buf << "genes (kai): #{@kai}\n\n" buf << Genome.new( @kai ).build_tables ## puts buf buf end |
#fmt_kai(kai) ⇒ Object
helpers
37 38 39 40 41 42 |
# File 'lib/copycats/reports/kitty.rb', line 37 def fmt_kai( kai ) ## format in groups of four (4) separated by space ## e.g. ccac7787fa7fafaa16467755f9ee444467667366cccceede ## : ccac 7787 fa7f afaa 1646 7755 f9ee 4444 6766 7366 cccc eede kai.reverse.gsub( /(.{4})/, '\1 ').reverse.strip end |
#save(path) ⇒ Object
28 29 30 31 32 |
# File 'lib/copycats/reports/kitty.rb', line 28 def save( path ) File.open( path, "w" ) do |f| f.write build end end |