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.
51 52 53 54 |
# File 'lib/zidian.rb', line 51 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.
49 50 51 |
# File 'lib/zidian.rb', line 49 def english @english end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
49 50 51 |
# File 'lib/zidian.rb', line 49 def id @id end |
#pinyin ⇒ Object (readonly)
Returns the value of attribute pinyin.
49 50 51 |
# File 'lib/zidian.rb', line 49 def @pinyin end |
#simplified ⇒ Object (readonly)
Returns the value of attribute simplified.
49 50 51 |
# File 'lib/zidian.rb', line 49 def simplified @simplified end |
#traditional ⇒ Object (readonly)
Returns the value of attribute traditional.
49 50 51 |
# File 'lib/zidian.rb', line 49 def traditional @traditional end |
Instance Method Details
#extract_attributes_from_string(line) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/zidian.rb', line 56 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 |