Class: Kotoshu::Dictionaries::Catalog::DictionaryEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/kotoshu/dictionaries/catalog.rb

Overview

Dictionary entry in the catalog

Instance Attribute Summary collapse

Instance Method Summary collapse

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_urlObject (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

#codeObject (readonly)

Returns the value of attribute code.



31
32
33
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31

def code
  @code
end

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

#formatObject (readonly)

Returns the value of attribute format.



31
32
33
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31

def format
  @format
end

#languageObject (readonly)

Returns the value of attribute language.



31
32
33
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31

def language
  @language
end

#licenseObject (readonly)

Returns the value of attribute license.



31
32
33
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31

def license
  @license
end

#metadataObject (readonly)

Returns the value of attribute metadata.



31
32
33
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31

def name
  @name
end

#regionObject (readonly)

Returns the value of attribute region.



31
32
33
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31

def region
  @region
end

#sourceObject (readonly)

Returns the value of attribute source.



31
32
33
# File 'lib/kotoshu/dictionaries/catalog.rb', line 31

def source
  @source
end

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

#descriptionString

Returns Human-readable description.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    true if this is a Hunspell dictionary



82
83
84
# File 'lib/kotoshu/dictionaries/catalog.rb', line 82

def hunspell?
  @format == :hunspell
end

#loadKotoshu::Dictionary::Base

Load this dictionary from URL

Returns:



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.

Returns:

  • (Boolean)

    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