Class: Potpourri::Field

Inherits:
Object
  • Object
show all
Includes:
Titleize
Defined in:
lib/models/field.rb

Direct Known Subclasses

ExportableField, ImportableField

Defined Under Namespace

Classes: Unexportable, Unimportable

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Titleize

#titleize

Constructor Details

#initialize(name, options = {}) ⇒ Field

Returns a new instance of Field.



10
11
12
13
14
15
# File 'lib/models/field.rb', line 10

def initialize(name, options = {})
  @export_method = options[:export_method] || name.to_sym
  @import_method = options[:import_method] || "#{ name }=".to_sym
  @header = options[:header] || titleize(name)
  @name = name.to_sym
end

Instance Attribute Details

#export_methodObject (readonly)

Returns the value of attribute export_method.



8
9
10
# File 'lib/models/field.rb', line 8

def export_method
  @export_method
end

#headerObject (readonly)

Returns the value of attribute header.



8
9
10
# File 'lib/models/field.rb', line 8

def header
  @header
end

#import_methodObject (readonly)

Returns the value of attribute import_method.



8
9
10
# File 'lib/models/field.rb', line 8

def import_method
  @import_method
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/models/field.rb', line 8

def name
  @name
end

Instance Method Details

#export(resource) ⇒ Object

Raises:



30
31
32
33
# File 'lib/models/field.rb', line 30

def export(resource)
  raise Unexportable unless exportable?
  resource.public_send export_method
end

#exportable?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/models/field.rb', line 21

def exportable?
  true
end

#import(resource, value) ⇒ Object

Raises:



25
26
27
28
# File 'lib/models/field.rb', line 25

def import(resource, value)
  raise Unimportable unless importable?
  resource.public_send import_method, value
end

#importable?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/models/field.rb', line 17

def importable?
  true
end