Class: RibitData::Page
- Inherits:
-
Object
- Object
- RibitData::Page
- Includes:
- Assert, Observable
- Defined in:
- lib/ribit/ribitdata.rb
Overview
This class models one page.
NOTE:
- page id is unique only inside one category
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#add_metadata(key, value) ⇒ Object
Adds MetaData key-value pair.
-
#full_id ⇒ Object
Returns the full id, category.id + page.id separated by ::.
-
#full_name ⇒ Object
Returns the fullname, category + name separated by ::.
-
#initialize(id, name, category) ⇒ Page
constructor
A new instance of Page.
-
#to_document ⇒ Object
Returns page data in XML format = REXML::Element.
Methods included from Assert
assert, #assert, assert_nil, #assert_nil, #assert_not_nil, assert_not_nil, raise_exception
Constructor Details
#initialize(id, name, category) ⇒ Page
Returns a new instance of Page.
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/ribit/ribitdata.rb', line 329 def initialize( id, name, category) assert_not_nil( id, "id was nil for a page" ) assert_not_nil( name, "name was nil for page #{id}" ) assert_not_nil( category, "category was nil for page #{id}" ) # allow to use Fixnum (decimal number) as a ID => convert to String @id = id.to_s @name = name @title = name @data = '' # metadata is empty by default @metadata = Hash.new @category = category @category.add_page( self ) end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
323 324 325 |
# File 'lib/ribit/ribitdata.rb', line 323 def category @category end |
#data ⇒ Object
Returns the value of attribute data.
323 324 325 |
# File 'lib/ribit/ribitdata.rb', line 323 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
323 324 325 |
# File 'lib/ribit/ribitdata.rb', line 323 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
323 324 325 |
# File 'lib/ribit/ribitdata.rb', line 323 def @metadata end |
#name ⇒ Object
Returns the value of attribute name.
323 324 325 |
# File 'lib/ribit/ribitdata.rb', line 323 def name @name end |
#title ⇒ Object
Returns the value of attribute title.
323 324 325 |
# File 'lib/ribit/ribitdata.rb', line 323 def title @title end |
Instance Method Details
#add_metadata(key, value) ⇒ Object
Adds MetaData key-value pair
368 369 370 |
# File 'lib/ribit/ribitdata.rb', line 368 def ( key, value ) @metadata[key] = value end |
#full_id ⇒ Object
- Returns the full id, category.id + page.id separated by
363 364 365 |
# File 'lib/ribit/ribitdata.rb', line 363 def full_id return @category.id.to_s + "::" + @id.to_s end |
#full_name ⇒ Object
- Returns the fullname, category + name separated by
358 359 360 |
# File 'lib/ribit/ribitdata.rb', line 358 def full_name return @category.full_name + "::" + @name end |
#to_document ⇒ Object
Returns page data in XML format = REXML::Element
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/ribit/ribitdata.rb', line 373 def to_document element = REXML::Element.new( 'page' ) # TODO: handle case where data-ref name = REXML::Element.new( 'name' ) title = REXML::Element.new( 'title' ) data = REXML::Element.new( 'data' ) REXML::CData.new( @name, true, name ) REXML::CData.new( @title, true, title ) REXML::CData.new( @data, true, data ) element.add_element( name ) element.add_element( title ) element.add_element( data ) = REXML::Element.new( 'metadata' ) @metadata.each do |key, value| propEle = REXML::Element.new( 'property' ) propEle.attributes['name'] = key propEle.attributes['value'] = value .add_element( propEle ) end # Add metadata element only if there is data if ( .size() > 0 ) element.add_element( ) end return element end |