class Ehpt::CreateStoryAttributes

Constants

ARRAY_TYPE_ATTRIBUTES
FLOAT_TYPE_ATTRIBUES
INT_ARRAY_TYPE_ATTRIBUTES
INT_TYPE_ATTRIBUTES

Attributes

row[R]

Public Class Methods

new(row) click to toggle source
Calls superclass method Ehpt::Base::new
# File lib/ehpt/create_story_attributes.rb, line 13
def initialize(row)
  @row = row
  super
end

Public Instance Methods

call() click to toggle source
# File lib/ehpt/create_story_attributes.rb, line 18
def call
  story_attrs = row.to_h.compact
  story_attrs.each do |key, value|
    story_attrs[key] = value.to_i if INT_TYPE_ATTRIBUTES.include?(key)
    story_attrs[key] = value.to_f if FLOAT_TYPE_ATTRIBUES.include?(key)
    story_attrs[key] = value.split(',') if ARRAY_TYPE_ATTRIBUTES.include?(key)
    story_attrs[key] = value.split(',').map(&:to_i) if INT_ARRAY_TYPE_ATTRIBUTES.include?(key)
  end

  if story_attrs['story_type'] != 'feature' && !Ehpt.project.bugs_and_chores_are_estimatable
    story_attrs['estimate'] = nil
  end

  if story_attrs.has_key?('requested_by')
    user_id = get_user_id_from(story_attrs.delete('requested_by'))
    story_attrs['requested_by_id'] = user_id unless user_id.nil?
  end

  if story_attrs.has_key?('owners')
    owners = story_attrs.delete('owners').split(',')
    owner_ids = owners.map { |owner| get_user_id_from(owner.strip) }.compact
    story_attrs['owner_ids'] = owner_ids unless owner_ids.empty?
  end

  @data = story_attrs
rescue StandardError => e
  add_error({
    row: row.to_h,
    warnings: e.message
  })
end

Private Instance Methods

get_user_id_from(initial) click to toggle source
# File lib/ehpt/create_story_attributes.rb, line 52
def get_user_id_from(initial)
  user_id_getter = Ehpt::GetUserIdFromInitial.new(initial)
  user_id_getter.call

  if user_id_getter.error?
    add_warning({
      row: row.to_h,
      warnings: user_id_getter.errors
    })
    return
  end

  user_id_getter.data
end