Class: Kotoshu::Dictionaries::Catalog::DictionaryEntry
- Inherits:
-
Object
- Object
- Kotoshu::Dictionaries::Catalog::DictionaryEntry
- Defined in:
- lib/kotoshu/dictionaries/catalog.rb
Overview
Dictionary entry in the catalog
Instance Attribute Summary collapse
-
#aff_url ⇒ Object
readonly
Returns the value of attribute aff_url.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#dic_url ⇒ Object
readonly
Returns the value of attribute dic_url.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#license ⇒ Object
readonly
Returns the value of attribute license.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#word_count ⇒ Object
readonly
Returns the value of attribute word_count.
Instance Method Summary collapse
-
#description ⇒ String
Human-readable description.
-
#hunspell? ⇒ Boolean
True if this is a Hunspell dictionary.
-
#initialize(code:, name:, language:, format:, source:, license:, word_count:, dic_url:, region: nil, aff_url: nil, metadata: {}) ⇒ DictionaryEntry
constructor
A new instance of DictionaryEntry.
-
#load ⇒ Kotoshu::Dictionary::Base
Load this dictionary from URL.
-
#plain_text? ⇒ Boolean
True if this is a plain text dictionary.
Constructor Details
#initialize(code:, name:, language:, format:, source:, license:, word_count:, dic_url:, region: nil, aff_url: nil, metadata: {}) ⇒ DictionaryEntry
Returns a new instance of DictionaryEntry.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 35 def initialize(code:, name:, language:, format:, source:, license:, word_count:, dic_url:, region: nil, aff_url: nil, metadata: {}) @code = code @name = name @language = language @region = region @format = format @source = source @license = license @word_count = word_count @dic_url = dic_url @aff_url = aff_url @metadata = freeze end |
Instance Attribute Details
#aff_url ⇒ Object (readonly)
Returns the value of attribute aff_url.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def aff_url @aff_url end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def code @code end |
#dic_url ⇒ Object (readonly)
Returns the value of attribute dic_url.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def dic_url @dic_url end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def format @format end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def language @language end |
#license ⇒ Object (readonly)
Returns the value of attribute license.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def license @license end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def name @name end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def region @region end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def source @source end |
#word_count ⇒ Object (readonly)
Returns the value of attribute word_count.
31 32 33 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31 def word_count @word_count end |
Instance Method Details
#description ⇒ String
Returns Human-readable description.
76 77 78 79 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 76 def description region_part = @region ? " (#{@region})" : "" "#{@name}#{region_part} - #{@word_count} words" end |
#hunspell? ⇒ Boolean
Returns true if this is a Hunspell dictionary.
82 83 84 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 82 def hunspell? @format == :hunspell end |
#load ⇒ Kotoshu::Dictionary::Base
Load this dictionary from URL
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 53 def load case @format when :hunspell raise ArgumentError, "Missing aff_url for Hunspell dictionary" unless @aff_url Kotoshu::Dictionary::Hunspell.new( dic_path: @dic_url, aff_path: @aff_url, language_code: @code, metadata: @metadata ) when :plain_text Kotoshu::Dictionary::PlainText.new( @dic_url, language_code: @code, metadata: @metadata ) else raise ArgumentError, "Unknown format: #{@format}" end end |
#plain_text? ⇒ Boolean
Returns true if this is a plain text dictionary.
87 88 89 |
# File 'lib/kotoshu/dictionaries/catalog.rb', line 87 def plain_text? @format == :plain_text end |