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


448
449
450
# File 'lib/vortex_client.rb', line 448

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

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



442
443
444
# File 'lib/vortex_client.rb', line 442

def body
  @body
end

#filenameObject

Returns the value of attribute filename.



442
443
444
# File 'lib/vortex_client.rb', line 442

def filename
  @filename
end

#hideAdditionalContentObject

Returns the value of attribute hideAdditionalContent.



442
443
444
# File 'lib/vortex_client.rb', line 442

def hideAdditionalContent
  @hideAdditionalContent
end

#introductionObject

Returns the value of attribute introduction.



442
443
444
# File 'lib/vortex_client.rb', line 442

def introduction
  @introduction
end

#modifiedDateObject

Returns the value of attribute modifiedDate.



442
443
444
# File 'lib/vortex_client.rb', line 442

def modifiedDate
  @modifiedDate
end

#ownerObject

Returns the value of attribute owner.



442
443
444
# File 'lib/vortex_client.rb', line 442

def owner
  @owner
end

#pictureObject

Returns the value of attribute picture.



442
443
444
# File 'lib/vortex_client.rb', line 442

def picture
  @picture
end

#publishDateObject

Returns the value of attribute publishDate.



442
443
444
# File 'lib/vortex_client.rb', line 442

def publishDate
  @publishDate
end

#tagsObject

Returns the value of attribute tags.



442
443
444
# File 'lib/vortex_client.rb', line 442

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



442
443
444
# File 'lib/vortex_client.rb', line 442

def title
  @title
end

#urlObject

Returns the value of attribute url.



442
443
444
# File 'lib/vortex_client.rb', line 442

def url
  @url
end

Instance Method Details

#contentObject



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/vortex_client.rb', line 473

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



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
# File 'lib/vortex_client.rb', line 570

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



468
469
470
# File 'lib/vortex_client.rb', line 468

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

#zzzzz_content_oldObject



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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/vortex_client.rb', line 514

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