Class: CiteProc::Variable

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable, Support::Attributes
Defined in:
lib/citeproc/variable.rb

Direct Known Subclasses

Date, Name

Class Attribute Summary collapse

Attributes included from Support::Attributes

#attributes, #key_filter, #value_filter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support::Attributes

#[], #[]=, included, #merge, #reverse_merge

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ Variable

Returns a new instance of Variable.

Yields:

  • (_self)

Yield Parameters:



51
52
53
54
# File 'lib/citeproc/variable.rb', line 51

def initialize(attributes={}, &block)
  parse!(attributes)
  yield self if block_given?
end

Class Attribute Details

.date_fieldsObject (readonly)

Returns the value of attribute date_fields.



35
36
37
# File 'lib/citeproc/variable.rb', line 35

def date_fields
  @date_fields
end

.filtersObject (readonly)

Returns the value of attribute filters.



35
36
37
# File 'lib/citeproc/variable.rb', line 35

def filters
  @filters
end

.name_fieldsObject (readonly)

Returns the value of attribute name_fields.



35
36
37
# File 'lib/citeproc/variable.rb', line 35

def name_fields
  @name_fields
end

.text_fieldsObject (readonly)

Returns the value of attribute text_fields.



35
36
37
# File 'lib/citeproc/variable.rb', line 35

def text_fields
  @text_fields
end

.typesObject (readonly)

Returns the value of attribute types.



35
36
37
# File 'lib/citeproc/variable.rb', line 35

def types
  @types
end

Class Method Details

.fieldsObject



37
38
39
# File 'lib/citeproc/variable.rb', line 37

def fields
  date_fields + name_fields + text_fields
end

.filter(id, key) ⇒ Object



41
42
43
# File 'lib/citeproc/variable.rb', line 41

def filter(id, key)
  Variable.filters[id][key]
end

.parse(values, name = nil) ⇒ Object



45
46
47
48
# File 'lib/citeproc/variable.rb', line 45

def parse(values, name=nil)
  values.is_a?(Array) ? values.map { |value| Variable.types[name].new(value) } :
    Variable.types[name].new(values)
end

Instance Method Details

#<=>(other) ⇒ Object



71
72
73
# File 'lib/citeproc/variable.rb', line 71

def <=>(other)
  strip_markup(to_s) <=> strip_markup(other.to_s)
end

#numeric?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/citeproc/variable.rb', line 61

def numeric?
  to_s =~ /\d/
end

#parse!(argument) ⇒ Object



56
57
58
59
# File 'lib/citeproc/variable.rb', line 56

def parse!(argument)
  argument = argument.to_hash if argument.is_a?(Variable)
  argument.is_a?(Hash) ?  self.merge!(argument) : self.value = argument.to_s
end

#to_iObject



66
67
68
# File 'lib/citeproc/variable.rb', line 66

def to_i
  to_s =~ /(-?\d[\d,\.]*)/ && $1.to_i || 0
end