Class: PBCore::V2::Base

Inherits:
Object
  • Object
show all
Includes:
SAXMachine
Defined in:
lib/pb_core/v2/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collection_groupObject



40
# File 'lib/pb_core/v2/base.rb', line 40

def self.collection_group; include PBCore::V2::CollectionGroup; end

.instantiation_groupObject



42
# File 'lib/pb_core/v2/base.rb', line 42

def self.instantiation_group; include PBCore::V2::InstantiationGroup; end

.source_version_groupObject



36
# File 'lib/pb_core/v2/base.rb', line 36

def self.source_version_group; include PBCore::V2::SourceVersionGroup; end

.start_end_time_groupObject



38
# File 'lib/pb_core/v2/base.rb', line 38

def self.start_end_time_group; include PBCore::V2::StartEndTimeGroup; end

Instance Method Details

#detect_element(element_name, options = {}) ⇒ Object

this is a handy method for getting info out of the doc since so many of the elements can be multiple, and you may need to pick just one, this method lets you do that by specifying the element, then how to select it by matching values to an attr. It can return just the first one of the element by default. It also can get the value from the element rather than return the element



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pb_core/v2/base.rb', line 51

def detect_element(element_name, options={})
  atr           = options[:match_attr] || :type
  values        = Array(options[:match_value] || nil)
  default_first = options.key?(:default_first) ? options[:default_first] : true
  method        = options.key?(:value) ? options[:value] : :value

  l = Array(self.send(element_name))
  return nil if l.size <= 0

  e = nil
  values.each{|v|
    e = l.detect do |i|
      # puts "detect: #{v.inspect} #{v.class.name} #{i.inspect}"
      case v.class.name
      when 'Regexp'
        # puts "match: #{v} #{element_value(i, atr)}"
        v =~ element_value(i, atr)
      else
        element_value(i, atr) == standardize(v)
      end
    end
    break if e
  }
  # puts "e: #{e.inspect}, m:#{method}, e.respond_to?(m): #{e.respond_to?(method)}"
  e = l.first if default_first && e.nil?
  e = (e && method && e.respond_to?(method)) ? e.send(method) : nil
  # puts "e: #{e.inspect}"
  return e
end