Class: DJNML::Modification

Inherits:
Object
  • Object
show all
Defined in:
lib/djnml/modification.rb

Defined Under Namespace

Classes: Mdata, XMLText

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Modification

Returns a new instance of Modification.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
# File 'lib/djnml/modification.rb', line 32

def initialize(args = {})

  @publisher = args[:publisher] if args[:publisher]
  @doc_date  = Time.parse(args[:doc_date]) if args[:doc_date]
  @product   = args[:product] if args[:product]
  @seq       = args[:seq].to_i if args[:seq]
  xml        = args[:xml] if args[:xml]

  if xml && xml.is_a?(Nokogiri::XML::Element)
    @xpath     = xml['xpath']

    if mdata = xml.search('djn-mdata').to_a.first
      @mdata = Mdata.new(mdata)
    end

    if headline = xml.search('headline').to_a.first
      @headline = headline.text.strip
    end

    if text = xml.search('text').to_a.first
      @text = XMLText.new(text)
    end

    if text = xml.search('summary').to_a.first
      @summary = XMLText.new(text)
    end

    if press = xml.search('djn-press-cutout').to_a.first
      @press_cutout = press.text.strip
    end

    if urgency = xml.search('djn-urgency').to_a.first
      @urgency = urgency.text.strip
    end
  else
    @publisher    = args['publisher'] if args['publisher']
    @doc_date     = Time.parse(args['doc_date']) if args['doc_date']
    @product      = args['product'] if args['product']
    @seq          = args['seq'].to_i if args['seq']
    @mdata        = Mdata.new(args['mdata']) if args['mdata']
    @headline     = args['headline'] if args['headline']
    @text         = XMLText.new(args['text']) if args['text']
    @summary      = XMLText.new(args['summary']) if args['summary']
    @press_cutout = args['press_cutout'] if args['press_cutout']
    @urgency      = args['urgency'] if args['urgency']
  end
end

Instance Attribute Details

#doc_dateObject (readonly)

Returns the value of attribute doc_date.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def doc_date
  @doc_date
end

#headlineObject (readonly)

Returns the value of attribute headline.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def headline
  @headline
end

#mdataObject (readonly)

Returns the value of attribute mdata.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def mdata
  @mdata
end

#press_cutoutObject (readonly)

Returns the value of attribute press_cutout.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def press_cutout
  @press_cutout
end

#productObject (readonly)

Returns the value of attribute product.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def product
  @product
end

#publisherObject (readonly)

Returns the value of attribute publisher.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def publisher
  @publisher
end

#seqObject (readonly)

Returns the value of attribute seq.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def seq
  @seq
end

#summaryObject (readonly)

Returns the value of attribute summary.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def summary
  @summary
end

#textObject (readonly)

Returns the value of attribute text.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def text
  @text
end

#urgencyObject (readonly)

Returns the value of attribute urgency.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def urgency
  @urgency
end

#xpathObject (readonly)

Returns the value of attribute xpath.



29
30
31
# File 'lib/djnml/modification.rb', line 29

def xpath
  @xpath
end

Instance Method Details

#fields_to_modifyObject



81
82
83
84
85
86
87
88
89
# File 'lib/djnml/modification.rb', line 81

def fields_to_modify
  fields = []
  [:mdata, :headline, :text, :urgency, :press_cutout, :summary].each do |f|
    if self.send(f)
      fields << f
    end
  end
  fields
end