Class: Puree::XMLExtractor::Resource

Inherits:
Base
  • Object
show all
Defined in:
lib/puree/xml_extractor/resource.rb

Overview

Resource XML extractor.

Instance Method Summary collapse

Methods inherited from Base

#xpath_query_for_multi_value, #xpath_query_for_single_value

Constructor Details

#initialize(xml:) ⇒ Resource

Returns a new instance of Resource.



9
10
11
# File 'lib/puree/xml_extractor/resource.rb', line 9

def initialize(xml:)
  super
end

Instance Method Details

#createdTime?

Returns:

  • (Time, nil)


28
29
30
# File 'lib/puree/xml_extractor/resource.rb', line 28

def created
  Time.parse xpath_query_for_single_value('/created')
end

#get_data?Boolean

Is there any data after get? For a response that provides a count of the results.

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/puree/xml_extractor/resource.rb', line 21

def get_data?
  path = service_xpath_count
  xpath_result = @doc.xpath path
  xpath_result.text.strip === '1' ? true : false
end

#localeString?

Locale (e.g. en-GB)

Returns:

  • (String, nil)


44
45
46
47
# File 'lib/puree/xml_extractor/resource.rb', line 44

def locale
  str = xpath_query_for_single_value '/@locale'
  str.tr('_','-') if str
end

#modifiedTime?

Returns:

  • (Time, nil)


33
34
35
# File 'lib/puree/xml_extractor/resource.rb', line 33

def modified
  Time.parse xpath_query_for_single_value('/modified')
end

#uuidString?

Returns:

  • (String, nil)


38
39
40
# File 'lib/puree/xml_extractor/resource.rb', line 38

def uuid
  xpath_query_for_single_value '/@uuid'
end

#xpath_query(path) ⇒ Object

content based



14
15
16
17
# File 'lib/puree/xml_extractor/resource.rb', line 14

def xpath_query(path)
  path_from_root = service_xpath path
  @doc.xpath path_from_root
end