Class: GenesPage
- Inherits:
-
Object
- Object
- GenesPage
- Defined in:
- lib/kittypedia/pages/genes.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#make_rows(items, columns: 2) ⇒ Object
helpers.
- #make_table(traits) ⇒ Object
- #save(path) ⇒ Object
Instance Method Details
#build ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kittypedia/pages/genes.rb', line 4 def build buf = "" buf << "# Genes (#{TraitType.size} x 4)\n\n" headings = [] TraitType.each do |tt| anchor = "#{tt.name} #{tt.code}".downcase.gsub( ' ', '-' ) headings << "[#{tt.name} (#{tt.code})](##{anchor})" end buf << headings.join( " • " ) buf << "\n\n" TraitType.each do |tt| buf << "## #{tt.name} (#{tt.code})\n\n" buf << "_Genes #{tt.genes}_\n\n" buf << make_table( tt.traits ) buf << "\n\n" end puts buf buf end |
#make_rows(items, columns: 2) ⇒ Object
helpers
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/kittypedia/pages/genes.rb', line 80 def make_rows( items, columns: 2 ) offset = items.size / columns pp offset rows = [] offset.times.with_index do |row| ## note: construct [items[row],items[offset+row],items[offset*2+row], ...] rows << columns.times.with_index.map { |col| items[offset*col+row] } end rows end |
#make_table(traits) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/kittypedia/pages/genes.rb', line 32 def make_table( traits ) rows = make_rows( traits, columns: 2 ) ## was 4 ## pp rows buf = "" buf << "|Kai|Code|Name |Kai|Code|Name |\n" buf << "|--:|---:|-------------|--:|---:|------------|\n" rows.each do |row| buf << "| " parts = row.map do |trait| kai = trait.kai ## binary = "%05b" % Kai::NUM[kai] code = trait.code name = trait.name tier = trait.tier_roman ## e.g. I,II,III, etc. : String if name.nil? ## note: so far x/31 trait is unknown/undefined!!! if kai == "x" cattribute = "?" elsif trait.type.key == :secret cattribute = "? #{tier}" ## unknown unknown else ## "anonymous / unnamed" gene / trait cattribute = "∅ #{tier}" ## known unknown :-) end else if name.downcase.start_with?( "totesbasic" ) ## note: special case for three totesbasic traits q = "totesbasic" else q = name end cattribute = "**[#{name}](#{kitties_search_url(q)})** #{tier}" end "#{kai} | #{code} | #{cattribute}" end buf << parts.join( " | " ) buf << " |\n" end buf end |
#save(path) ⇒ Object
93 94 95 96 97 |
# File 'lib/kittypedia/pages/genes.rb', line 93 def save( path ) File.open( path, "w:utf-8" ) do |f| f.write build end end |