Class: AbstractModel
- Inherits:
-
Object
- Object
- AbstractModel
- Includes:
- LoggerSetup
- Defined in:
- lib/cuker/writer_helper/abstract_model.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Array
Writable array of rows of data Defaults to [].
-
#title ⇒ Array
Writable rows of title Defaults to [].
Attributes included from LoggerSetup
Instance Method Summary collapse
- #get_keys_ary(ary_of_hshs) ⇒ Object
-
#get_tags(hsh) ⇒ Object
def padded_surround item, sep, pad “#sep#pad#item#pad#sep” end.
- #get_values_ary(ary_of_hshs) ⇒ Object
-
#initialize(_model_input = []) ⇒ AbstractModel
constructor
A new instance of AbstractModel.
-
#name_merge(hsh) ⇒ Object
utility methods used by any model.
- #simple_surround(item, sep) ⇒ Object
- #surround(ary, sep) ⇒ Object
- #union(feat_tags, tags) ⇒ Object
Methods included from LoggerSetup
#init_logger, reset_appender_log_levels
Constructor Details
#initialize(_model_input = []) ⇒ AbstractModel
Returns a new instance of AbstractModel.
23 24 25 26 27 |
# File 'lib/cuker/writer_helper/abstract_model.rb', line 23 def initialize _model_input = [] init_logger @title = [] @data = [] end |
Instance Attribute Details
#data ⇒ Array
Returns writable array of rows of data Defaults to [].
21 22 23 |
# File 'lib/cuker/writer_helper/abstract_model.rb', line 21 def data @data end |
#title ⇒ Array
Returns writable rows of title Defaults to [].
17 18 19 |
# File 'lib/cuker/writer_helper/abstract_model.rb', line 17 def title @title end |
Instance Method Details
#get_keys_ary(ary_of_hshs) ⇒ Object
33 34 35 |
# File 'lib/cuker/writer_helper/abstract_model.rb', line 33 def get_keys_ary ary_of_hshs ary_of_hshs.map(&:keys).flatten end |
#get_tags(hsh) ⇒ Object
def padded_surround item, sep, pad
"#{sep}#{pad}#{item}#{pad}#{sep}"
end
67 68 69 70 71 72 73 74 |
# File 'lib/cuker/writer_helper/abstract_model.rb', line 67 def (hsh) if hsh[:tags] and hsh[:tags].any? hsh[:tags].map {|tag| tag[:name]} else @log.warn "No Tags found in #{hsh[:keyword]} @ #{@file_path}" [] end end |
#get_values_ary(ary_of_hshs) ⇒ Object
29 30 31 |
# File 'lib/cuker/writer_helper/abstract_model.rb', line 29 def get_values_ary ary_of_hshs ary_of_hshs.map(&:values).flatten end |
#name_merge(hsh) ⇒ Object
utility methods used by any model
40 41 42 43 44 45 46 |
# File 'lib/cuker/writer_helper/abstract_model.rb', line 40 def name_merge hsh str = "" @log.warn "name merge for #{hsh}" str += hsh[:name].strip.force_encoding("UTF-8") if hsh[:name] str += " - #{hsh[:description].strip.force_encoding("UTF-8")}" if hsh[:description] str end |
#simple_surround(item, sep) ⇒ Object
59 60 61 |
# File 'lib/cuker/writer_helper/abstract_model.rb', line 59 def simple_surround item, sep "#{sep}#{item}#{sep}" end |
#surround(ary, sep) ⇒ Object
53 54 55 56 57 |
# File 'lib/cuker/writer_helper/abstract_model.rb', line 53 def surround ary, sep # "#{sep}#{ary.is_a?(Array)? ary.join(sep) : ary}#{sep}" # "#{sep}#{ary.join(sep)}#{sep}" simple_surround ary.join(sep), sep end |
#union(feat_tags, tags) ⇒ Object
49 50 51 |
# File 'lib/cuker/writer_helper/abstract_model.rb', line 49 def union , (.to_set | .to_set).to_a # union end |