pb_core 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,13 +41,24 @@ module PBCore
41
41
 
42
42
  def self.instantiation_group; include PBCore::V2::InstantiationGroup; end
43
43
 
44
- def detect_element(elements_name, atr=:type, values=nil, use_first=true)
45
- l = Array(self.send(elements_name))
46
- values = Array(values)
44
+
45
+ # this is a handy method for getting info out of the doc
46
+ # since so many of the elements can be multiple,
47
+ # and you may need to pick just one, this method lets you do that
48
+ # by specifying the element, then how to select it by matching values to an attr.
49
+ # It can return just the first one of the element by default.
50
+ # It also can get the value from the element rather than return the element
51
+ def detect_element(element_name, options={})
52
+ atr = options[:match_attr] || :type
53
+ values = Array(options[:match_value] || nil)
54
+ default_first = options.key?(:default_first) ? options[:default_first] : true
55
+ method = options.key?(:value) ? options[:value] : :value
56
+
57
+ l = Array(self.send(element_name))
47
58
  return nil if l.size <= 0
48
59
 
49
60
  e = nil
50
- Array(values).each{|v|
61
+ values.each{|v|
51
62
  e = l.detect do |i|
52
63
  # puts "detect: #{v.inspect} #{v.class.name} #{i.inspect}"
53
64
  case v.class.name
@@ -60,7 +71,10 @@ module PBCore
60
71
  end
61
72
  break if e
62
73
  }
63
- e = l.first if use_first && e.nil?
74
+ # puts "e: #{e.inspect}, m:#{method}, e.respond_to?(m): #{e.respond_to?(method)}"
75
+ e = l.first if default_first && e.nil?
76
+ e = (e && method && e.respond_to?(method)) ? e.send(method) : nil
77
+ # puts "e: #{e.inspect}"
64
78
  return e
65
79
  end
66
80
 
@@ -1,3 +1,3 @@
1
1
  module PBCore
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pb_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-27 00:00:00.000000000 Z
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sax-machine
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  segments:
80
80
  - 0
81
- hash: -2261759994973944842
81
+ hash: -2707617022099910108
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  segments:
89
89
  - 0
90
- hash: -2261759994973944842
90
+ hash: -2707617022099910108
91
91
  requirements: []
92
92
  rubyforge_project:
93
93
  rubygems_version: 1.8.23