class Renogen::ChangeLog::Item

Object to represent single change item

Attributes

change[RW]
group_name[R]
ticket_id[R]

Public Class Methods

new(ticket_id, group_name, change, options={}) click to toggle source
# File lib/renogen/change_log/item.rb, line 8
def initialize(ticket_id, group_name, change, options={})
  @ticket_id = ticket_id
  @group_name = group_name
  @change = change
end

Public Instance Methods

each() { |item| ... } click to toggle source

Iterater for each item within the change

# File lib/renogen/change_log/item.rb, line 38
def each
  change.each do |item|
    yield item.to_s
  end
end
list?() click to toggle source

@return [Boolean] true if change is of type array

# File lib/renogen/change_log/item.rb, line 33
def list?
  change.is_a? Array
end
to_s() click to toggle source

Coverts the item into its string representation

@return [String]

# File lib/renogen/change_log/item.rb, line 17
def to_s
  return '' unless change

  case change.class.to_s
  when 'String'
    format_multiline(change)
  when 'Hash'
    format_oneline(change)
  when 'Array'
    format_array(change)
  else
    raise TypeError
  end
end

Private Instance Methods

config() click to toggle source
# File lib/renogen/change_log/item.rb, line 65
def config
  Config.instance
end
format_array(change) click to toggle source
# File lib/renogen/change_log/item.rb, line 50
def format_array(change)
  # TODO: should return a string
  change
end
format_multiline(change) click to toggle source
# File lib/renogen/change_log/item.rb, line 46
def format_multiline(change)
  change.gsub('\n', '\n \n ') + "\n"
end
format_oneline(change) click to toggle source
# File lib/renogen/change_log/item.rb, line 55
def format_oneline(change)
  # TODO: Refactor
  string = config.single_line_format.downcase.gsub('\n', '\n  ')
  config.supported_keys.each do |key|
    string = string.gsub(key, '#{change[\'' + key + '\']}')
  end
  ss = "\"#{string}\""
  eval(ss)
end