Permalink
Browse files

adds methods for iterating over hiragana rows/columns

  • Loading branch information...
1 parent 7d9b633 commit d075237567703188f623edc3e2f4ef14314e8251 @Najaf Najaf committed Apr 15, 2013
Showing with 84 additions and 2 deletions.
  1. +2 −0 .rspec
  2. +3 −2 kana-grid.gemspec
  3. +3 −0 lib/kana-grid.rb
  4. +28 −0 lib/kana-grid/hiragana.rb
  5. +47 −0 spec/hiragana_spec.rb
  6. +1 −0 spec/spec_helper.rb
View
@@ -0,0 +1,2 @@
+--color
+--format documentation
View
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
spec.version = Kana::Grid::VERSION
spec.authors = ["Najaf Ali"]
spec.email = ["ali@happybearsoftware.com"]
- spec.description = %q{TODO: Write a gem description}
- spec.summary = %q{TODO: Write a gem summary}
+ spec.description = %q{Write a gem description}
+ spec.summary = %q{Write a gem summary}
spec.homepage = ""
spec.license = "MIT"
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
+ spec.add_development_dependency "rspec"
end
View
@@ -0,0 +1,3 @@
+$: << File.dirname(__FILE__)
+
+autoload :Hiragana, 'kana-grid/hiragana'
@@ -0,0 +1,28 @@
+class Hiragana
+ class << self
+ def columns(opts = { align: false })
+ align = opts[:align]
+ [ %w(あ い う え お),
+ %w(か き く け こ),
+ %w(さ し す せ そ),
+ %w(た ち つ て と),
+ %w(な に ぬ ね の),
+ %w(は ひ ふ へ ほ),
+ %w(ま み む め も),
+ align ? ['', '', '', '', ''] : %w(や ゆ よ),
+ %w(ら り る れ ろ),
+ align ? ['', '', '', '', ''] : %w(わ を),
+ align ? ['', '', '', '', ''] : %w()
+ ]
+ end
+
+ def rows
+ @rows ||= [ ['', '', '', '', '', '', '', '', '', '', ''],
+ ['', '', '', '', '', '', '', '', '', '', '' ],
+ ['', '', '', '', '', '', '', '', '', '', '' ],
+ ['', '', '', '', '', '', '', '', '', '', '' ],
+ ['', '', '', '', '', '', '', '', '', '', '' ]
+ ]
+ end
+ end
+end
View
@@ -0,0 +1,47 @@
+require 'spec_helper'
+
+describe Hiragana do
+ describe '.columns' do
+ it 'returns all hiragana columns' do
+ Hiragana.columns.should == [ %w(あ い う え お),
+ %w(か き く け こ),
+ %w(さ し す せ そ),
+ %w(た ち つ て と),
+ %w(な に ぬ ね の),
+ %w(は ひ ふ へ ほ),
+ %w(ま み む め も),
+ %w(や ゆ よ),
+ %w(ら り る れ ろ),
+ %w(わ を),
+ %w() ]
+ end
+
+ it 'adds empty space for alignment if align: true' do
+ Hiragana.columns(align: true).should == [ %w(あ い う え お),
+ %w(か き く け こ),
+ %w(さ し す せ そ),
+ %w(た ち つ て と),
+ %w(な に ぬ ね の),
+ %w(は ひ ふ へ ほ),
+ %w(ま み む め も),
+ ['', '', '', '', ''],
+ %w(ら り る れ ろ),
+ ['', '', '', '', ''],
+ ['', '', '', '', '']
+ ]
+ end
+ end
+
+ describe '.rows' do
+ it 'returns all hiragana rows with alignment' do
+ rows = [ ['', '', '', '', '', '', '', '', '', '', ''],
+ ['', '', '', '', '', '', '', '', '', '', '' ],
+ ['', '', '', '', '', '', '', '', '', '', '' ],
+ ['', '', '', '', '', '', '', '', '', '', '' ],
+ ['', '', '', '', '', '', '', '', '', '', '' ]
+ ]
+
+ Hiragana.rows.should == rows
+ end
+ end
+end
View
@@ -0,0 +1 @@
+require './lib/kana-grid'

0 comments on commit d075237

Please sign in to comment.