Class: Zidian::Word
- Inherits:
-
Object
- Object
- Zidian::Word
- Defined in:
- lib/zidian.rb
Instance Attribute Summary collapse
-
#english ⇒ Object
readonly
Returns the value of attribute english.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#pinyin ⇒ Object
readonly
Returns the value of attribute pinyin.
-
#simplified ⇒ Object
readonly
Returns the value of attribute simplified.
-
#traditional ⇒ Object
readonly
Returns the value of attribute traditional.
Instance Method Summary collapse
- #extract_attributes_from_string(line) ⇒ Object
-
#initialize(line, id = nil) ⇒ Word
constructor
A new instance of Word.
Constructor Details
#initialize(line, id = nil) ⇒ Word
Returns a new instance of Word.
34 35 36 37 |
# File 'lib/zidian.rb', line 34 def initialize(line, id=nil) @id = id extract_attributes_from_string(line.strip!) end |
Instance Attribute Details
#english ⇒ Object (readonly)
Returns the value of attribute english.
32 33 34 |
# File 'lib/zidian.rb', line 32 def english @english end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
32 33 34 |
# File 'lib/zidian.rb', line 32 def id @id end |
#pinyin ⇒ Object (readonly)
Returns the value of attribute pinyin.
32 33 34 |
# File 'lib/zidian.rb', line 32 def @pinyin end |
#simplified ⇒ Object (readonly)
Returns the value of attribute simplified.
32 33 34 |
# File 'lib/zidian.rb', line 32 def simplified @simplified end |
#traditional ⇒ Object (readonly)
Returns the value of attribute traditional.
32 33 34 |
# File 'lib/zidian.rb', line 32 def traditional @traditional end |
Instance Method Details
#extract_attributes_from_string(line) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/zidian.rb', line 39 def extract_attributes_from_string(line) if line =~ /^[0-9]*:/ @id = line.gsub!(/^[0-9]*:/).to_a.first.gsub(':','').to_i end @traditional = line.match(/^[^\s]+/)[0] @simplified = line.match(/\s[^\s]+/)[0].strip @pinyin = line.match(/\[.+?\]/)[0].gsub(/[\[\]]/,'') @english = line.scan(/\/[^\/]+/).collect{|e| e.gsub(/[\/]/,'')} end |