Class: Earl::EntityBase

Inherits:
HashInquirer show all
Defined in:
lib/earl/entity_base.rb

Direct Known Subclasses

EmailEntity, URLEntity

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HashInquirer

#method_missing

Constructor Details

#initialize(source) ⇒ EntityBase

Returns a new instance of EntityBase.



3
4
5
# File 'lib/earl/entity_base.rb', line 3

def initialize( source )
  super parser.parse( source ).resolve rescue raise InvalidURLError
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Earl::HashInquirer

Class Method Details

.part_accessor(*parts, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/earl/entity_base.rb', line 11

def self.part_accessor( *parts, &block )
  parts.each do |part|
    define_method part do
      if self[ part ].is_a? String
        StringInquirer.new self[ part ]
      else
        self[ part ]
      end
    end
    define_method :"#{part}=" do |value|
      self[ part ] = value
      yield value if block_given?
    end
  end
end

Instance Method Details

#to_sObject



7
8
9
# File 'lib/earl/entity_base.rb', line 7

def to_s
  assembler.assemble self
end