Class: Rexport::DataField

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/rexport/data_field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Stores the name and method of the export data item



9
10
11
12
13
# File 'lib/rexport/data_field.rb', line 9

def initialize(name, options = {})
  @name   = name.to_s
  @method = options[:method].blank? ? self.name : options[:method].to_s
  @type   = options[:type]
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



6
7
8
# File 'lib/rexport/data_field.rb', line 6

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rexport/data_field.rb', line 6

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/rexport/data_field.rb', line 6

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object

Sort by name



16
17
18
# File 'lib/rexport/data_field.rb', line 16

def <=>(other)
  name <=> other.name
end

#association_nameObject

Returns the first association name from a method chain string. If the string does not contain the dot operator a nil is returned.

Examples:

"assocation.method" # => "association"
"assocation_one.assocation_two.method" # => "assocation_one"
"method" # => nil


28
29
30
# File 'lib/rexport/data_field.rb', line 28

def association_name
  method[0..(first_dot_index - 1)] if first_dot_index.present?
end