class DJNML::Modification

Attributes

doc_date[R]
headline[R]
mdata[R]
press_cutout[R]
product[R]
publisher[R]
seq[R]
summary[R]
text[R]
urgency[R]
xpath[R]

Public Class Methods

new(args = {}) click to toggle source
# 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

Public Instance Methods

fields_to_modify() click to toggle source
# 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