Class: WWW::Delicious::Post
- Inherits:
-
Object
- Object
- WWW::Delicious::Post
- Defined in:
- lib/www/delicious/post.rb
Instance Attribute Summary collapse
-
#notes ⇒ Object
TODO: filter and validate.
-
#others ⇒ Object
TODO: filter and validate.
-
#replace ⇒ Object
Returns the value of attribute replace.
-
#shared ⇒ Object
Returns the value of attribute shared.
-
#tags ⇒ Object
TODO: filter and validate.
-
#time ⇒ Object
TODO: filter and validate.
-
#title ⇒ Object
TODO: filter and validate.
-
#uid ⇒ Object
TODO: filter and validate.
-
#url ⇒ Object
TODO: filter and validate.
Instance Method Summary collapse
-
#api_valid? ⇒ Boolean
Returns wheter this object is valid for an API request.
-
#initialize(values_or_rexml) {|_self| ... } ⇒ Post
constructor
Creates a new
WWW::Delicious::Post
with given values. -
#initialize_from_hash(values) ⇒ Object
Initializes
WWW::Delicious::Post
from anHash
. -
#initialize_from_rexml(element) ⇒ Object
Initializes
WWW::Delicious::Post
from a REXML fragment. -
#to_params ⇒ Object
Returns a params-style representation suitable for API calls.
Constructor Details
#initialize(values_or_rexml) {|_self| ... } ⇒ Post
Creates a new WWW::Delicious::Post
with given values. If values_or_rexml
is a REXML element, the element is parsed and all values assigned to this instance attributes.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/www/delicious/post.rb', line 32 def initialize(values_or_rexml, &block) # :yields: post case values_or_rexml when Hash initialize_from_hash(values_or_rexml) when REXML::Element initialize_from_rexml(values_or_rexml) else raise ArgumentError, 'Expected `values_or_rexml` to be `Hash` or `REXML::Element`' end yield(self) if block_given? self end |
Instance Attribute Details
#notes ⇒ Object
TODO: filter and validate
23 24 25 |
# File 'lib/www/delicious/post.rb', line 23 def notes @notes end |
#others ⇒ Object
TODO: filter and validate
23 24 25 |
# File 'lib/www/delicious/post.rb', line 23 def others @others end |
#replace ⇒ Object
Returns the value of attribute replace.
24 25 26 |
# File 'lib/www/delicious/post.rb', line 24 def replace @replace end |
#shared ⇒ Object
Returns the value of attribute shared.
24 25 26 |
# File 'lib/www/delicious/post.rb', line 24 def shared @shared end |
#tags ⇒ Object
TODO: filter and validate
23 24 25 |
# File 'lib/www/delicious/post.rb', line 23 def @tags end |
#time ⇒ Object
TODO: filter and validate
23 24 25 |
# File 'lib/www/delicious/post.rb', line 23 def time @time end |
#title ⇒ Object
TODO: filter and validate
23 24 25 |
# File 'lib/www/delicious/post.rb', line 23 def title @title end |
#uid ⇒ Object
TODO: filter and validate
23 24 25 |
# File 'lib/www/delicious/post.rb', line 23 def uid @uid end |
#url ⇒ Object
TODO: filter and validate
23 24 25 |
# File 'lib/www/delicious/post.rb', line 23 def url @url end |
Instance Method Details
#api_valid? ⇒ Boolean
106 107 108 |
# File 'lib/www/delicious/post.rb', line 106 def api_valid? return !(url.nil? or url.empty? or title.nil? or title.empty?) end |
#initialize_from_hash(values) ⇒ Object
Initializes WWW::Delicious::Post
from an Hash
.
50 51 52 53 54 55 56 |
# File 'lib/www/delicious/post.rb', line 50 def initialize_from_hash(values) %w(url title notes others udi tags time shared replace).each do |v| self.instance_variable_set("@#{v}".to_sym(), values[v.to_sym()]) end self.shared = true if self.shared.nil? self.replace = true if self.replace.nil? end |
#initialize_from_rexml(element) ⇒ Object
Initializes WWW::Delicious::Post
from a REXML fragment.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/www/delicious/post.rb', line 62 def initialize_from_rexml(element) self.url = element.attribute_value(:href) { |v| URI.parse(v) } self.title = element.attribute_value(:description) self.notes = element.attribute_value(:extended) self.others = element.attribute_value(:others).to_i() # cast nil to 0 self.uid = element.attribute_value(:hash) self. = element.attribute_value(:tag) { |v| v.split(' ') }.to_a() self.time = element.attribute_value(:time) { |v| Time.parse(v) } self.shared = element.attribute_value(:shared) { |v| v == 'no' ? false : true } end |
#to_params ⇒ Object
Returns a params-style representation suitable for API calls.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/www/delicious/post.rb', line 77 def to_params() params = {} params[:url] = self.url params[:description] = self.title params[:extended] = self.notes if self.notes params[:shared] = self.shared params[:tags] = self..join(' ') if self. params[:replace] = self.replace params[:dt] = WWW::Delicious::TIME_CONVERTER.call(self.time) if self.time return params end |