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.



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

#englishObject (readonly)

Returns the value of attribute english.



32
33
34
# File 'lib/zidian.rb', line 32

def english
  @english
end

#idObject (readonly)

Returns the value of attribute id.



32
33
34
# File 'lib/zidian.rb', line 32

def id
  @id
end

#pinyinObject (readonly)

Returns the value of attribute pinyin.



32
33
34
# File 'lib/zidian.rb', line 32

def pinyin
  @pinyin
end

#simplifiedObject (readonly)

Returns the value of attribute simplified.



32
33
34
# File 'lib/zidian.rb', line 32

def simplified
  @simplified
end

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