Class: Para::ModelFieldParsers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/para/model_field_parsers/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, fields_hash, mappings) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
# File 'lib/para/model_field_parsers/base.rb', line 10

def initialize(model, fields_hash, mappings)
  @model = model
  @fields_hash = fields_hash
  @mappings = mappings
end

Instance Attribute Details

#fields_hashObject (readonly)

Returns the value of attribute fields_hash.



8
9
10
# File 'lib/para/model_field_parsers/base.rb', line 8

def fields_hash
  @fields_hash
end

#mappingsObject (readonly)

Returns the value of attribute mappings.



8
9
10
# File 'lib/para/model_field_parsers/base.rb', line 8

def mappings
  @mappings
end

#modelObject (readonly)

Returns the value of attribute model.



8
9
10
# File 'lib/para/model_field_parsers/base.rb', line 8

def model
  @model
end

Class Method Details

.register(key, parser) ⇒ Object



4
5
6
# File 'lib/para/model_field_parsers/base.rb', line 4

def self.register(key, parser)
  ModelFieldParsers.registered_parsers[key] = parser
end

Instance Method Details

#applicable?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/para/model_field_parsers/base.rb', line 16

def applicable?
  true
end

#find_attributes_for_mapping(type) ⇒ Object



20
21
22
# File 'lib/para/model_field_parsers/base.rb', line 20

def find_attributes_for_mapping(type)
  mappings.select { |k, v| v == type.to_s }.keys.map(&:to_sym)
end