Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions yohei_tangstad/a_to_map.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'rspec'

def a_to_map(a)
target = a[0]
m = Hash.new
a.slice(1..-1).each {|value| m[value] = target}
m
end

describe "a_to_map" do
it "should convert array with number to map to number" do
a_to_map(["0", "a", "b"]).should == {"a" => "0", "b" => "0"}
end
end
11 changes: 11 additions & 0 deletions yohei_tangstad/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
0 | まる、ま | れい、れ | おう、ぜろ、ぜ
1 | ひとつ、ひと、ひ | いち、い | わん
2 | ふたつ、ふた、ふ | に | つ
3 | みつ、み | さん、さ | すりー
4 | よん、よ、よつ | し | ふぉー
5 | いつつ、いつ | ご、こ | ふぁいぶ、ふぁいぶ
6 | むつ、む | ろく、ろ | しっくす
7 | ななつ、なな、な | しち | せぶん、せゔん
8 | やつ、や | はち、は、ば | えーと
9 | ここのつ、こ | きゅう、く | ないん
10 | とお | じゅう、じ | てん
45 changes: 45 additions & 0 deletions yohei_tangstad/dict-creator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

require 'rspec'

class String
def split_characters(chars)
array = [strip]
chars.each_char{ |c|
temp_array = []
array.each{|s|
temp_array.concat s.split(c)
temp_array.delete_if{|a| a==""}
}
array = temp_array
}
# result = split('|')
return array.map{|l| l.strip}
end
end

#"".split_characters
given_data = open('./data.txt').read

given_data.each_line {|d|
puts d.split_characters('|、').to_s
}



describe "split_characters" do
it "should split on character" do
"one two".split_characters(" ").should == ["one", "two"]
end
it "should split on multiple characters" do
"one two,three, four".split_characters(" ,").should == ["one", "two", "three", "four"]
end
it "should split our input properly" do
"0 | まる、ま | れい、れ | おう 、ぜろ、ぜ ".split_characters("| 、").should == ["0", "まる", "ま", "れい", "れ", "おう", "ぜろ", "ぜ"]
end
end





21 changes: 21 additions & 0 deletions yohei_tangstad/reader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# encoding: UTF-8

require 'rspec'

class TableReader
def parseline(line)
a = Array.new
a.push(line)
a
end
end

describe TableReader do
describe "#parseline" do
it "should return all hiragana words in a line" do
tr = TableReader.new
tr.parseline("ひらがな").should == ["ひらがな"]
end
end
end