Class: Zidian::Word

Inherits:
Object
  • Object
show all
Defined in:
lib/zidian.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#englishObject (readonly)

Returns the value of attribute english.



49
50
51
# File 'lib/zidian.rb', line 49

def english
  @english
end

#idObject (readonly)

Returns the value of attribute id.



49
50
51
# File 'lib/zidian.rb', line 49

def id
  @id
end

#pinyinObject (readonly)

Returns the value of attribute pinyin.



49
50
51
# File 'lib/zidian.rb', line 49

def pinyin
  @pinyin
end

#simplifiedObject (readonly)

Returns the value of attribute simplified.



49
50
51
# File 'lib/zidian.rb', line 49

def simplified
  @simplified
end

#traditionalObject (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