Class: ArcWeld::Archive
- Inherits:
-
Object
- Object
- ArcWeld::Archive
- Defined in:
- lib/arc_weld/archive.rb
Constant Summary collapse
- BUILD_VERSION =
'6.5.1.1952.1'
- BUILD_TIME =
'3-6-2015_17:2:26'
- TIME_FORMAT =
'%m-%d-%Y_%H:%M:%S'
- PARSE_DEFAULT =
Nokogiri::XML::ParseOptions::DEFAULT_XML
- PARSE_VALIDATE =
Nokogiri::XML::ParseOptions::DEFAULT_XML | Nokogiri::XML::ParseOptions::DTDLOAD
- ARCHIVE_DTD =
"../../schema/xml/archive/arcsight-archive.dtd"
Instance Attribute Summary collapse
-
#createTime ⇒ Object
Returns the value of attribute createTime.
-
#dtd_location ⇒ Object
Returns the value of attribute dtd_location.
-
#resources ⇒ Object
Returns the value of attribute resources.
Instance Method Summary collapse
- #add(*items) ⇒ Object
- #add_item(item) ⇒ Object
- #archive_creation_parameters ⇒ Object
- #create_time ⇒ Object
- #dtd(location = ARCHIVE_DTD) ⇒ Object
- #include_list ⇒ Object
-
#initialize(*args) ⇒ Archive
constructor
A new instance of Archive.
- #render ⇒ Object
- #resource_content ⇒ Object
- #to_h ⇒ Object
- #xml(options = PARSE_DEFAULT) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Archive
Returns a new instance of Archive.
14 15 16 17 18 19 20 |
# File 'lib/arc_weld/archive.rb', line 14 def initialize(*args) Hash[*args].each {|k,v| self.send(format('%s=',k),v)} @resources ||= [] @createTime ||= Time.new @dtd_location ||= ARCHIVE_DTD self end |
Instance Attribute Details
#createTime ⇒ Object
Returns the value of attribute createTime.
3 4 5 |
# File 'lib/arc_weld/archive.rb', line 3 def createTime @createTime end |
#dtd_location ⇒ Object
Returns the value of attribute dtd_location.
3 4 5 |
# File 'lib/arc_weld/archive.rb', line 3 def dtd_location @dtd_location end |
#resources ⇒ Object
Returns the value of attribute resources.
3 4 5 |
# File 'lib/arc_weld/archive.rb', line 3 def resources @resources end |
Instance Method Details
#add(*items) ⇒ Object
30 31 32 |
# File 'lib/arc_weld/archive.rb', line 30 def add(*items) items.each { |item| add_item(item) } end |
#add_item(item) ⇒ Object
26 27 28 |
# File 'lib/arc_weld/archive.rb', line 26 def add_item(item) resources.push(item) unless resources.include?(item) end |
#archive_creation_parameters ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/arc_weld/archive.rb', line 38 def archive_creation_parameters acp = { ArchiveCreationParameters: { :action => 'insert', 'excludeReferenceIDs/' => '', :format => 'default', 'formatRoot/' => '' } } if resources.empty? acp[:ArchiveCreationParameters]['include/'] = '' else acp[:ArchiveCreationParameters][:include] = { :list! => include_list } end Gyoku.xml(acp, {key_converter: :none}) end |
#create_time ⇒ Object
57 58 59 |
# File 'lib/arc_weld/archive.rb', line 57 def create_time @createTime.strftime(TIME_FORMAT) end |
#dtd(location = ARCHIVE_DTD) ⇒ Object
34 35 36 |
# File 'lib/arc_weld/archive.rb', line 34 def dtd(location=ARCHIVE_DTD) format('<!DOCTYPE archive SYSTEM "%s">', dtd_location) end |
#include_list ⇒ Object
22 23 24 |
# File 'lib/arc_weld/archive.rb', line 22 def include_list resources.map {|g| g.ref.render }.join('') end |
#render ⇒ Object
78 79 80 |
# File 'lib/arc_weld/archive.rb', line 78 def render Gyoku.xml(to_h, {key_converter: :none} ) end |
#resource_content ⇒ Object
61 62 63 |
# File 'lib/arc_weld/archive.rb', line 61 def resource_content resources.map {|res| res.render }.join('') end |
#to_h ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/arc_weld/archive.rb', line 65 def to_h archive_h = { :archive! => archive_creation_parameters + resource_content, :attributes! => { :archive! => { :buildVersion => BUILD_VERSION, :buildTime => BUILD_TIME, :createTime => create_time } } } end |
#xml(options = PARSE_DEFAULT) ⇒ Object
82 83 84 |
# File 'lib/arc_weld/archive.rb', line 82 def xml(=PARSE_DEFAULT) Nokogiri.XML(dtd + render, nil, 'UTF-8', ) end |