Class: Potpourri::Field
- Inherits:
-
Object
- Object
- Potpourri::Field
- Includes:
- Titleize
- Defined in:
- lib/models/field.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Unexportable, Unimportable
Instance Attribute Summary collapse
-
#export_method ⇒ Object
readonly
Returns the value of attribute export_method.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#import_method ⇒ Object
readonly
Returns the value of attribute import_method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #export(resource) ⇒ Object
- #exportable? ⇒ Boolean
- #import(resource, value) ⇒ Object
- #importable? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ Field
constructor
A new instance of Field.
Methods included from 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, = {}) @export_method = [:export_method] || name.to_sym @import_method = [:import_method] || "#{ name }=".to_sym @header = [:header] || titleize(name) @name = name.to_sym end |
Instance Attribute Details
#export_method ⇒ Object (readonly)
Returns the value of attribute export_method.
8 9 10 |
# File 'lib/models/field.rb', line 8 def export_method @export_method end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
8 9 10 |
# File 'lib/models/field.rb', line 8 def header @header end |
#import_method ⇒ Object (readonly)
Returns the value of attribute import_method.
8 9 10 |
# File 'lib/models/field.rb', line 8 def import_method @import_method end |
#name ⇒ Object (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
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
21 22 23 |
# File 'lib/models/field.rb', line 21 def exportable? true end |
#import(resource, value) ⇒ Object
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
17 18 19 |
# File 'lib/models/field.rb', line 17 def importable? true end |