Sha256: d95092da6e2ef4136bd3a5e9ef83e28d1b934991150339b095f5f5b4c2d07aee

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

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.5.1.7 lib/jldrill/model/items/edict/Usage.rb