Class: RSimpy::Parameters
- Inherits:
-
Object
- Object
- RSimpy::Parameters
- Defined in:
- lib/parameters.rb
Constant Summary collapse
- RSIMPY_SOURCE =
'rsimpy'
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #access_type(type) ⇒ Object
- #add(key, value) ⇒ Object
- #add_src ⇒ Object
- #build_tag_string(tags) ⇒ Object
- #date(date, to = nil) ⇒ Object
- #format(key, value) ⇒ Object
- #format_access_type(type) ⇒ Object
- #format_date(date) ⇒ Object
- #format_uri(uri) ⇒ Object
- #has_key?(key) ⇒ Boolean
- #href(uri) ⇒ Object
-
#initialize(params = {}) ⇒ Parameters
constructor
A new instance of Parameters.
- #limit(limit) ⇒ Object
- #note(note) ⇒ Object
- #q(query) ⇒ Object
- #tags(tags) ⇒ Object
- #title(title) ⇒ Object
- #to_querystring ⇒ Object
- #url_nickname(nickname) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Parameters
Returns a new instance of Parameters.
7 8 9 |
# File 'lib/parameters.rb', line 7 def initialize params={} @params = params end |
Instance Method Details
#[](key) ⇒ Object
11 12 13 |
# File 'lib/parameters.rb', line 11 def [] key @params[key] end |
#[]=(key, value) ⇒ Object
15 16 17 |
# File 'lib/parameters.rb', line 15 def []= key, value @params[key] = value end |
#access_type(type) ⇒ Object
86 87 88 |
# File 'lib/parameters.rb', line 86 def access_type type add :accessType, type end |
#add(key, value) ⇒ Object
70 71 72 |
# File 'lib/parameters.rb', line 70 def add key, value @params[key] = value end |
#add_src ⇒ Object
36 37 38 |
# File 'lib/parameters.rb', line 36 def add_src @params[:src] = RSIMPY_SOURCE unless @params.has_key? :src end |
#build_tag_string(tags) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/parameters.rb', line 58 def build_tag_string if .class == Array .collect{|a| a + ", "}.to_s.chop.chop else end end |
#date(date, to = nil) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/parameters.rb', line 106 def date date, to=nil if to add :afterDate, format_date(date) add :beforeDate, format_date(to) else add :date, format_date(date) end end |
#format(key, value) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/parameters.rb', line 40 def format key, value case key when(:href) format_uri(value) when(:tags) build_tag_string value when(:accessType) format_access_type value else value end end |
#format_access_type(type) ⇒ Object
66 67 68 |
# File 'lib/parameters.rb', line 66 def format_access_type type type == :private ? 0 : 1 end |
#format_date(date) ⇒ Object
116 117 118 |
# File 'lib/parameters.rb', line 116 def format_date date date.strftime("%Y-%m-%d") end |
#format_uri(uri) ⇒ Object
53 54 55 56 |
# File 'lib/parameters.rb', line 53 def format_uri uri uri = 'http://' + uri unless uri[0..6] == 'http://' uri end |
#has_key?(key) ⇒ Boolean
19 20 21 |
# File 'lib/parameters.rb', line 19 def has_key? key @params.has_key? key end |
#href(uri) ⇒ Object
78 79 80 |
# File 'lib/parameters.rb', line 78 def href uri add :href, uri end |
#limit(limit) ⇒ Object
102 103 104 |
# File 'lib/parameters.rb', line 102 def limit limit add :limit, limit end |
#note(note) ⇒ Object
94 95 96 |
# File 'lib/parameters.rb', line 94 def note note add :note, note end |
#q(query) ⇒ Object
98 99 100 |
# File 'lib/parameters.rb', line 98 def q query add :q, query end |
#tags(tags) ⇒ Object
82 83 84 |
# File 'lib/parameters.rb', line 82 def add :tags, end |
#title(title) ⇒ Object
74 75 76 |
# File 'lib/parameters.rb', line 74 def title title add :title, title end |
#to_querystring ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/parameters.rb', line 23 def to_querystring output = "" add_src @params.sort {|a,b| a.to_s<=>b.to_s}.each do |key, value| value = format key, value value = CGI.escape(value) if value.class == String output << "#{key.to_s}=#{value}&" end output.chop end |
#url_nickname(nickname) ⇒ Object
90 91 92 |
# File 'lib/parameters.rb', line 90 def url_nickname nickname add :urlNickname, nickname end |