Class: AbstractModel

Inherits:
Object
  • Object
show all
Includes:
LoggerSetup
Defined in:
lib/cuker/writer_helper/abstract_model.rb

Direct Known Subclasses

Cuker::CsvModel, Cuker::JiraModel

Instance Attribute Summary collapse

Attributes included from LoggerSetup

#log

Instance Method Summary collapse

Methods included from LoggerSetup

#init_logger, reset_appender_log_levels

Constructor Details

#initialize(_model_input = []) ⇒ 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

#dataArray



21
22
23
# File 'lib/cuker/writer_helper/abstract_model.rb', line 21

def data
  @data
end

#titleArray



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 get_tags(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 feat_tags, tags
  (feat_tags.to_set | tags.to_set).to_a # union

end