Class: Nokogiri::XML::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/jiraSOAP/nokogiri_extensions.rb

Overview

Monkey (Freedom) patches to Nokogiri

Instance Method Summary collapse

Instance Method Details

#children_as_object(klass) ⇒ Object

Parameters:

  • klass (Class)

    the JIRA object you want to make



59
60
61
# File 'lib/jiraSOAP/nokogiri_extensions.rb', line 59

def children_as_object klass
  klass.new_with_xml self
end

#children_as_objects(klass) ⇒ Array

Returns an array of klass objects.

Parameters:

  • klass (Class)

    the object you want an array of

Returns:

  • (Array)

    an array of klass objects



65
66
67
# File 'lib/jiraSOAP/nokogiri_extensions.rb', line 65

def children_as_objects klass
  children.map { |node| klass.new_with_xml node }
end

#contents_of_childrenObject

Ideally this method will return an array of strings, but this may not always be the case.



54
55
56
# File 'lib/jiraSOAP/nokogiri_extensions.rb', line 54

def contents_of_children
  children.map { |val| val.content }
end

#to_booleanBoolean

We assume that the boolean is encoded as as string, because that how JIRA is doing right now, but the XML schema allows a boolean to be encoded as 0/1 numbers instead.

Returns:

  • (Boolean)


31
32
33
# File 'lib/jiraSOAP/nokogiri_extensions.rb', line 31

def to_boolean
  content == 'true' # || content == 1
end

#to_color_tripleArray(String,String,String)? Also known as: to_colour_triple

This is a bit naive, but should be sufficient for its purpose.

Returns:

  • (Array(String,String,String), nil)


45
46
47
48
# File 'lib/jiraSOAP/nokogiri_extensions.rb', line 45

def to_color_triple
  return if (temp = content).empty?
  temp.match(/#(..)(..)(..)/).captures
end

#to_iFixnum

Returns:

  • (Fixnum)


6
7
8
# File 'lib/jiraSOAP/nokogiri_extensions.rb', line 6

def to_i
  content.to_i
end

#to_iso_dateTime?

Returns:

  • (Time, nil)


11
12
13
14
# File 'lib/jiraSOAP/nokogiri_extensions.rb', line 11

def to_iso_date
  return if (temp = content).empty?
  Time.iso8601 temp
end

#to_natural_dateTime?

Parses non-strict date strings into Time objects.

Returns:

  • (Time, nil)


20
21
22
23
# File 'lib/jiraSOAP/nokogiri_extensions.rb', line 20

def to_natural_date
  return if (temp = content).empty?
  Time.new temp
end

#to_urlURI::HTTP, ...

Returns:

  • (URI::HTTP, NSURL, nil)


36
37
38
39
# File 'lib/jiraSOAP/nokogiri_extensions.rb', line 36

def to_url
  return if (temp = content).empty?
  JIRA.url_class.send JIRA.url_init_method, temp
end