Class: Kotoshu::Readers::LookupBuilder
- Inherits:
-
Object
- Object
- Kotoshu::Readers::LookupBuilder
- Defined in:
- lib/kotoshu/readers/lookup_builder.rb
Overview
Builder for creating Lookup::Lookuper instances from Hunspell data.
This class can either read from files or accept pre-read aff/dic data.
Instance Attribute Summary collapse
-
#aff_data ⇒ Object
readonly
Returns the value of attribute aff_data.
-
#aff_path ⇒ Object
readonly
Returns the value of attribute aff_path.
-
#dic_path ⇒ Object
readonly
Returns the value of attribute dic_path.
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Class Method Summary collapse
-
.from_data(aff_data, words) ⇒ LookupBuilder
Create a new LookupBuilder from pre-read data.
Instance Method Summary collapse
-
#build ⇒ Algorithms::Lookup::Lookuper
Build the Lookuper instance.
-
#initialize(aff_path, dic_path, encoding: 'UTF-8', script: :latin) ⇒ LookupBuilder
constructor
Create a new LookupBuilder from file paths.
Constructor Details
#initialize(aff_path, dic_path, encoding: 'UTF-8', script: :latin) ⇒ LookupBuilder
Create a new LookupBuilder from file paths.
35 36 37 38 39 40 41 42 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 35 def initialize(aff_path, dic_path, encoding: 'UTF-8', script: :latin) @aff_path = aff_path @dic_path = dic_path @encoding = encoding @script = script @aff_data = nil @words = nil end |
Instance Attribute Details
#aff_data ⇒ Object (readonly)
Returns the value of attribute aff_data.
27 28 29 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 27 def aff_data @aff_data end |
#aff_path ⇒ Object (readonly)
Returns the value of attribute aff_path.
27 28 29 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 27 def aff_path @aff_path end |
#dic_path ⇒ Object (readonly)
Returns the value of attribute dic_path.
27 28 29 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 27 def dic_path @dic_path end |
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
27 28 29 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 27 def encoding @encoding end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
27 28 29 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 27 def script @script end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
27 28 29 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 27 def words @words end |
Class Method Details
.from_data(aff_data, words) ⇒ LookupBuilder
Create a new LookupBuilder from pre-read data.
49 50 51 52 53 54 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 49 def self.from_data(aff_data, words) builder = new(nil, nil) builder.instance_variable_set(:@aff_data, aff_data) builder.instance_variable_set(:@words, words) builder end |
Instance Method Details
#build ⇒ Algorithms::Lookup::Lookuper
Build the Lookuper instance.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/kotoshu/readers/lookup_builder.rb', line 59 def build # Read files if data not already provided aff_data_to_use = @aff_data || read_aff_data words_to_use = @words || read_dic_data(aff_data_to_use) # Build the aff structure for Lookuper aff = build_aff_structure(aff_data_to_use) # Build the dic structure for Lookuper dic = build_dic_structure(words_to_use) # Create and return the Lookuper Algorithms::Lookup::Lookuper.new(aff, dic) end |