class DocuBot::MetaSection

Constants

META_SEPARATOR
NIL_CASTABLE

Attributes

__contents__[R]

Public Class Methods

new( attrs={}, file_path=nil ) click to toggle source
# File lib/docubot/metasection.rb, line 24
def initialize( attrs={}, file_path=nil )
        @attrs = {}
        attrs.each{ |key,value| self[key]=value }
        if file_path && File.exists?( file_path )
                parts = IO.read( file_path, encoding:'utf-8' ).split( META_SEPARATOR, 2 )
                if parts.length > 1
                        parts.first.scan(/.+/) do |line|
                                next if line =~ /^\s*#/
                                next unless line.include?(':')
                                attribute, value = line.split(':',2).map{ |str| str.strip }
                                self[attribute] = value
                        end
                end
                @__contents__ = parts.last && parts.last.strip
        end
end

Public Instance Methods

[]( attribute ) click to toggle source
# File lib/docubot/metasection.rb, line 45
def []( attribute )
        @attrs.has_key?( attribute ) ? @attrs[attribute] : NIL_CASTABLE
end
[]=( attribute, value ) click to toggle source
# File lib/docubot/metasection.rb, line 49
def []=( attribute, value )
        @attrs[attribute.to_s] = value.extend(Castable)
end
has_key?( key ) click to toggle source
# File lib/docubot/metasection.rb, line 41
def has_key?( key )
        @attrs.has_key?( key )
end
method_missing( method, *args ) click to toggle source
# File lib/docubot/metasection.rb, line 53
def method_missing( method, *args )
        key=method.to_s
        case key[-1..-1] # the last character of the method name
                when '=' then self[key[0..-2]] = args.first
                else self[key]
        end
end