Class: Hip3::CustomFieldLookup

Inherits:
Object
  • Object
show all
Defined in:
app/models/hip3/custom_field_lookup.rb

Overview

are only findable by name of the field header as configured in HIP admin, and then only by seeing what index in a list that header is, and then finding the corresponding indexed value! This object does that work for us, and caches it's calcuations while it's at it. One of these objects has it's own rexml doc representing a particular bib with item info, because the answer may be different for different bibs!

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_header_list) ⇒ CustomFieldLookup



13
14
15
16
# File 'app/models/hip3/custom_field_lookup.rb', line 13

def initialize(a_header_list)
  self.header_list = a_header_list
  
end

Instance Attribute Details

#header_listObject

Returns the value of attribute header_list



11
12
13
# File 'app/models/hip3/custom_field_lookup.rb', line 11

def header_list
  @header_list
end

Instance Method Details

#index_for(label) ⇒ Object



19
20
21
# File 'app/models/hip3/custom_field_lookup.rb', line 19

def index_for(label)
  return header_list.index(label)
end

#text_value_for(list, label) ⇒ Object

list can be either an array of strings, or a rexml element representing a <row> element for this item. In either case, we lookup the index i of label in our original header list, and then return the text value of element i in the list arg.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/hip3/custom_field_lookup.rb', line 27

def text_value_for(list, label )      
  i = index_for(label)
  return nil if i.nil?
    
  if ( list.kind_of?(Hpricot::Node) )
    # Assume they passed in a HIP 'row' element, turn it

    # into a nice array of strings. Can't figure out how

    # to test if it really is a 'row' element!

      list = list.search('/cell/data/text').collect {|e| e.inner_text}
  end
  
  return list.at( i )
    
end