Module: RSS::BaseModel

Instance Method Summary collapse

Methods included from Utils

element_initialize_arguments?, get_file_and_line_from_caller, new_with_value_if_need, to_class_name

Instance Method Details

#install_date_element(tag_name, uri, occurs, name = nil, type = nil, disp_name = nil) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/rss/rss.rb', line 279

def install_date_element(tag_name, uri, occurs, name=nil, type=nil, disp_name=nil)
  name ||= tag_name
  type ||= :w3cdtf
  disp_name ||= name
  self::ELEMENTS << name
  add_need_initialize_variable(name)
  install_model(tag_name, uri, occurs, name)

  # accessor
  convert_attr_reader name
  date_writer(name, type, disp_name)

  install_element(name) do |n, elem_name|
    <<-EOC
    if @#{n}
      rv = "\#{indent}<#{elem_name}>"
      value = CGI.escapeHTML(@#{n}.#{type}.to_s)
      if need_convert
        rv << convert(value)
      else
        rv << value
      end
        rv << "</#{elem_name}>"
      rv
    else
      ''
    end
EOC
  end

end

#install_have_child_element(tag_name, uri, occurs, name = nil, type = nil) ⇒ Object Also known as: install_have_attribute_element



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/rss/rss.rb', line 205

def install_have_child_element(tag_name, uri, occurs, name=nil, type=nil)
  name ||= tag_name
  add_need_initialize_variable(name)
  install_model(tag_name, uri, occurs, name)

  writer_type, reader_type = type
  def_corresponded_attr_writer name, writer_type
  def_corresponded_attr_reader name, reader_type
  install_element(name) do |n, elem_name|
    <<-EOC
    if @#{n}
      "\#{@#{n}.to_s(need_convert, indent)}"
    else
      ''
    end
EOC
  end
end

#install_have_children_element(tag_name, uri, occurs, name = nil, plural_name = nil) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/rss/rss.rb', line 225

def install_have_children_element(tag_name, uri, occurs, name=nil, plural_name=nil)
  name ||= tag_name
  plural_name ||= "#{name}s"
  add_have_children_element(name, plural_name)
  add_plural_form(name, plural_name)
  install_model(tag_name, uri, occurs, plural_name, true)

  def_children_accessor(name, plural_name)
  install_element(name, "s") do |n, elem_name|
    <<-EOC
    rv = []
    @#{n}.each do |x|
      value = "\#{x.to_s(need_convert, indent)}"
      rv << value if /\\A\\s*\\z/ !~ value
    end
    rv.join("\n")
EOC
  end
end

#install_text_element(tag_name, uri, occurs, name = nil, type = nil, disp_name = nil) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/rss/rss.rb', line 245

def install_text_element(tag_name, uri, occurs, name=nil, type=nil,
                         disp_name=nil)
  name ||= tag_name
  disp_name ||= name
  self::ELEMENTS << name unless self::ELEMENTS.include?(name)
  add_need_initialize_variable(name)
  install_model(tag_name, uri, occurs, name)

  def_corresponded_attr_writer(name, type, disp_name)
  def_corresponded_attr_reader(name, type || :convert)
  install_element(name) do |n, elem_name|
    <<-EOC
    if respond_to?(:#{n}_content)
      content = #{n}_content
    else
      content = @#{n}
    end
    if content
      rv = "\#{indent}<#{elem_name}>"
      value = CGI.escapeHTML(content.to_s)
      if need_convert
        rv << convert(value)
      else
        rv << value
      end
        rv << "</#{elem_name}>"
      rv
    else
      ''
    end
EOC
  end
end