Module: Jira::Inflectors

Defined in:
lib/jira/inflectors.rb

Defined Under Namespace

Classes: BaseInflector, CompositeInflector, IndexedValueInflector, LabelInflector, NumberFieldInflector, StringInflector

Class Method Summary collapse

Class Method Details

.factory(type, value) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/jira/inflectors.rb', line 60

def self.factory(type, value)
  case type.to_s
    when 'FreeTextField', 'TextField', 'URLField'
      StringInflector.new(value)
    when 'GroupPicker', 'UserPicker', 'SingleVersionPicker', 'SingleSelect'
      IndexedValueInflector.new(value, :name)
    when 'MultiUserPicker', 'MultiGroupPicker', 'MultiSelect'
      inner = ensure_list(value) do |value|
        value.map do |v|
          begin
            factory(type.sub('Multi', ''), v)
          rescue
            factory(type.sub('Multi', 'Single'), v)
          end
        end
      end
      CompositeInflector.new(*inner)
    when 'Labels'
      ensure_list(value) do |value|
        CompositeInflector.new(*(value.map { |v| LabelInflector.new(v) }))
      end
    when 'SelectList'
      IndexedValueInflector.new(value, :value)
    when 'ProjectPicker'
      IndexedValueInflector.new(value, :key)
    else
      inflector = "#{type}Inflector".to_sym
      unless const_defined?(inflector)
        raise "Unrecognized field type \"#{type}\""
      end
      const_get(inflector).new(value)
  end
end