Sha256: 24f0b4b454141aa48a5b6ea3126b72119e0924170ae306906424c04bf05ac191

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

# encoding: utf-8
require "jldrill/model/items/edict/Definition"

module JLDrill
    
    # Holds a collection of definitions that defines a typical usage
    # for the word.  It also holds an index number for the usage.
    class Usage

    	attr_reader :index, :types, :definitions
    	attr_writer :index

    	def initialize
    		@definitions = []
    		@index = 0
    	end
    	
    	def Usage.create(string, index=0)
    	    usage = Usage.new
    	    usage.index = index
    	    usage.parse(string)
    	    usage
    	end
    	
    	def parse(string)
    		string.split("/").each do |definition|
    			defn = Definition.create(definition)
    			@definitions.push(defn)
    		end
    	end
    	
    	# Returns all the types in the definitions
    	def allTypes
    		retVal = []
    		@definitions.each do |defn|
    			retVal += defn.types
    		end
    		retVal
    	end

         # Returns all the values for the definitions
    	def allDefinitions
    		retVal = []
    		@definitions.each do |defn|
    			retVal.push defn.value unless defn.value == ""
    		end
    		retVal
    	end
    	
    	def to_s
    	    retVal = ""
    	    if index != 0
    	        retVal += "(" + index.to_s + ")"
    	    end
    	    retVal += @definitions.join("/")
    	end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jldrill-0.6.0.1 lib/jldrill/model/items/edict/Usage.rb