Class: Vortex::StructuredArticle

Inherits:
HtmlArticle show all
Defined in:
lib/vortex_client.rb

Overview

Vortex article stored as JSON data.

Instance Attribute Summary collapse

Attributes inherited from HtmlArticle

#author, #date, #publishedDate

Instance Method Summary collapse

Methods inherited from HtmlArticle

#escape_html

Constructor Details

#initialize(options = {}) ⇒ StructuredArticle

Create an article Options:

:title => "Title" mandatory


489
490
491
# File 'lib/vortex_client.rb', line 489

def initialize(options={})
  options.each{|k,v|send("#{k}=",v)}
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



483
484
485
# File 'lib/vortex_client.rb', line 483

def body
  @body
end

#filenameObject

Returns the value of attribute filename.



483
484
485
# File 'lib/vortex_client.rb', line 483

def filename
  @filename
end

#hideAdditionalContentObject

Returns the value of attribute hideAdditionalContent.



483
484
485
# File 'lib/vortex_client.rb', line 483

def hideAdditionalContent
  @hideAdditionalContent
end

#introductionObject

Returns the value of attribute introduction.



483
484
485
# File 'lib/vortex_client.rb', line 483

def introduction
  @introduction
end

#modifiedDateObject

Returns the value of attribute modifiedDate.



483
484
485
# File 'lib/vortex_client.rb', line 483

def modifiedDate
  @modifiedDate
end

#ownerObject

Returns the value of attribute owner.



483
484
485
# File 'lib/vortex_client.rb', line 483

def owner
  @owner
end

#pictureObject

Returns the value of attribute picture.



483
484
485
# File 'lib/vortex_client.rb', line 483

def picture
  @picture
end

#publishDateObject

Returns the value of attribute publishDate.



483
484
485
# File 'lib/vortex_client.rb', line 483

def publishDate
  @publishDate
end

#tagsObject

Returns the value of attribute tags.



483
484
485
# File 'lib/vortex_client.rb', line 483

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



483
484
485
# File 'lib/vortex_client.rb', line 483

def title
  @title
end

#urlObject

Returns the value of attribute url.



483
484
485
# File 'lib/vortex_client.rb', line 483

def url
  @url
end

Instance Method Details

#contentObject



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/vortex_client.rb', line 514

def content
  properties = { }
  if(body and body.size > 0)
    properties = properties.merge(:content => body)
  end

  if(tags and tags.kind_of?(Array) and tags.size > 0)then
    properties = properties.merge(:tags => tags)
  end

  if(author and author.size > 0)
    properties =  properties.merge(:author => author)
  end
  if(introduction and introduction.size > 0)
    properties = properties.merge(:introduction => introduction)
  end

  if(picture)
    properties = properties.merge(:picture => picture)
  end

  if(title)
    properties = properties.merge(:title => title)
  end

  if(@hideAdditionalContent != nil)then
    if(@hideAdditionalContent.kind_of?(FalseClass))
      value = "false"
    elsif(@hideAdditionalContent.kind_of?(TrueClass))then
      value = "true"
    elsif(@hideAdditionalContent.kind_of?(String))
      value = @hideAdditionalContent
    end
    properties = properties.merge(:hideAdditionalContent => value)
  end

  json = { :resourcetype => "structured-article"}.merge(:properties => properties).to_json

  return json
end

#propertiesObject



611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'lib/vortex_client.rb', line 611

def properties
  props = '<v:resourceType xmlns:v="vrtx">structured-article</v:resourceType>' +
    '<v:userSpecifiedCharacterEncoding xmlns:v="vrtx">utf-8</v:userSpecifiedCharacterEncoding>' +
    '<d:getcontenttype>application/json</d:getcontenttype>'

  if(@publishDate and @publishDate != "")
    if(@publishDate.kind_of? Time)
      @publishDate = @publishDate.httpdate.to_s
    end
    props += '<v:publish-date xmlns:v="vrtx">' + @publishDate + '</v:publish-date>'
  end

  if(date and date != "")
    if(date.kind_of? Time)
      date = @date.httpdate.to_s
    end
    if(@publishDate == nil or @publishDate != "")
      props += '<v:publish-date xmlns:v="vrtx">' + date + '</v:publish-date>'
    end
    props += '<d:getlastmodified>' + date + '</d:getlastmodified>' +
    '<v:contentLastModified xmlns:v="vrtx">' + date + '</v:contentLastModified>' +
    '<v:propertiesLastModified xmlns:v="vrtx">' + date + '</v:propertiesLastModified>' +
    '<v:creationTime xmlns:v="vrtx">' + date + '</v:creationTime>'
  end

  if(owner)
    props += '<owner xmlns="vrtx">' + owner + '</owner>'
  end

  if(author and author != "")
#        props += '<v:authors xmlns:v="vrtx">' +
#          '<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">' +
#             '<vrtx:value>' + author + '</vrtx:value>' +
#           '</vrtx:values>' +
#        '</v:authors>'
  end

  return props
end

#to_sObject



509
510
511
# File 'lib/vortex_client.rb', line 509

def to_s
  "#<Vortex::StructuredArticle "+instance_variables.collect{|var|var+": "+instance_variable_get(var).to_s}.join(",")+">"
end

#zzzzz_content_oldObject



555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
# File 'lib/vortex_client.rb', line 555

def zzzzz_content_old
  json = <<-EOF
  {
     "resourcetype": "structured-article",
     "properties": {
  EOF

  if(body and body.size > 0)
    tmp_body = body
    # Escape '"' and line shifts so html will be valid json data.
    tmp_body = tmp_body.gsub(/\r/,"\\\r").gsub(/\n/,"\\\n").gsub(/\"/,"\\\"") ## .to_json
    json += "           \"content\": \"#{tmp_body}\",\n"
  end

  if(tags and tags.kind_of?(Array) and tags.size > 0)
    json += "           \"tags\": ,\n"
    json += "             \"" + tags.join("\"\n, \"") + "\"\n"
  end

  if(author and author.size > 0)
    json += "           \"author\": [\"#{author}\"],\n"
  end
  json += "           \"title\": \"#{title}\",\n"
  if(introduction and introduction.size > 0)
    tmp_introduction = introduction
    tmp_introduction = tmp_introduction.gsub(/\r/,"\\\r")
    tmp_introduction = tmp_introduction.gsub(/\n/,"\\\n")
    tmp_introduction = tmp_introduction.gsub(/\"/,"\\\"")
    json += "           \"introduction\": \"#{tmp_introduction}\",\n"
  end
  if(picture)
    json += "           \"picture\": \"#{picture}\",\n"
  end
  if(@hideAdditionalContent != nil)then
    if(@hideAdditionalContent.kind_of?(FalseClass))
      value = "false"
    elsif(@hideAdditionalContent.kind_of?(TrueClass))then
      value = "true"
    elsif(@hideAdditionalContent.kind_of?(String))
      value = @hideAdditionalContent
    end
   json += <<-EOF
         "hideAdditionalContent": "#{value}"
   EOF
   end
   json += <<-EOF
       }
    }
    EOF

  # puts "DEBUG: json:" + json
  # puts

  return json
end