Sha256: 6fafcadcb0b19a0787438c2783ef522085242cc3fea1853da958201bd5dae06a
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
require "jldrill/model/items/edict/GrammarType" module JLDrill # Holds a definition for an Edict entry. Each definition # may have one or more type indicating its type of speach # (verb, noun, etc) class Definition DEFINITION_RE = /^(\(\S*\))\s?(.*)/ SEPARATOR_RE = /\)|,/ COMMA_RE = /[,]/ attr_reader :types, :value attr_writer :types, :value def initialize() @value = "" @types = [] end def Definition.create(string) definition = Definition.new definition.parse(string) definition end def parse(string) @types = [] while string =~ DEFINITION_RE types = GrammarType.create($1) if(types.empty?) # There were no types in the parenthesis, so it must # be part of the definition. @value += $1 + " " else @types += types end string = $2 end @value += string.gsub(COMMA_RE, "\\,") end def eql?(definition) @value.eql?(definition.value) && (@types.size == definition.types.size) && @types.all? do |x| definition.types.find do |y| x.eql?(y) end end end def to_s retVal = "" if @types.size > 0 retVal += "(" + @types.join(",") + ")" end retVal += @value retVal end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jldrill-0.5.1.7 | lib/jldrill/model/items/edict/Definition.rb |