Class: Ccp::Kvs::Tokyo::Info
- Inherits:
-
Object
- Object
- Ccp::Kvs::Tokyo::Info
- Defined in:
- lib/ccp/kvs/tokyo/info.rb
Class Method Summary collapse
-
.example ⇒ Object
example.
-
.parse(buf) ⇒ Object
parse.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #count ⇒ Object
-
#initialize ⇒ Info
constructor
instance methods.
Constructor Details
#initialize ⇒ Info
instance methods
51 52 53 |
# File 'lib/ccp/kvs/tokyo/info.rb', line 51 def initialize @hash = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args, &block) ⇒ Object (private)
64 65 66 67 68 69 70 |
# File 'lib/ccp/kvs/tokyo/info.rb', line 64 def method_missing(key, *args, &block) raise unless args.empty? raise unless self.class.respond_to?(key) cast = self.class.__send__(key) return self[key.to_s].__send__(cast) end |
Class Method Details
.example ⇒ Object
example
18 19 20 21 22 23 24 25 |
# File 'lib/ccp/kvs/tokyo/info.rb', line 18 def self.example parse(" path: /tmp/tc/foo.tch\n database type: hash database\n record number: 0\n size: 528704\n EOF\nend\n") |
.parse(buf) ⇒ Object
parse
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ccp/kvs/tokyo/info.rb', line 30 def self.parse(buf) # % tcamgr inform /tmp/tc/foo.tch # # path: /tmp/tc/foo.tch # database type: hash database # record number: 0 # size: 528704 # info = new buf.scan(/^([a-z ]+): (.*?)($|\Z)/mo).each do |key, val| key = key.strip.tr(' ', '_') val = val.strip info[key] = val end return info end |
Instance Method Details
#[](key) ⇒ Object
55 56 57 |
# File 'lib/ccp/kvs/tokyo/info.rb', line 55 def [](key) @hash[key] end |
#[]=(key, val) ⇒ Object
59 60 61 |
# File 'lib/ccp/kvs/tokyo/info.rb', line 59 def []=(key, val) @hash[key] = val end |
#count ⇒ Object
13 |
# File 'lib/ccp/kvs/tokyo/info.rb', line 13 def count; record_number; end |