dyoder-filebase 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/filebase/attributes.rb +11 -25
  2. metadata +1 -1
@@ -1,47 +1,33 @@
1
1
  module Attributes
2
2
 
3
- def initialize(hash = {} )
4
- attributes = hash
5
- end
3
+ def initialize( hash = {} ) ; self.attributes = hash ; end
6
4
 
7
5
  def attributes=( hash )
8
6
  # copy the hash, converting all keys to strings
9
7
  @attrs = hash.inject({}) { |h,p| k,v = p; h[k.to_s] = v; h }
10
8
  end
11
9
 
12
- def attributes
13
- @attrs ||= {}
14
- end
10
+ def attributes ; @attrs ||= {} ; end
15
11
 
16
12
  def method_missing(name,*args)
17
- name = name.to_s
18
- if name =~/=$/ and args.length == 1
19
- set(name[0..-2], args[0] )
20
- else
21
- get(name)
13
+ case args.length
14
+ when 0 then get( name.to_s )
15
+ when 1 then set( name.to_s[0..-2], args[0] )
16
+ else raise ArgumentError.new("#{args.length} for 0 or 1")
22
17
  end
23
18
  end
24
19
 
25
- def [](name)
26
- get(name)
27
- end
20
+ def [](name) ; get(name) ; end
28
21
 
29
- def []=(name,val)
30
- set(name,val)
31
- end
22
+ def []=(name,val) ; set(name,val) ; end
32
23
 
33
- def set(name, val)
34
- attributes[name.to_s] = val
35
- end
24
+ def set(name, val) ; attributes[name.to_s] = val ; end
36
25
 
37
26
  def get(name)
38
- rval = attributes[name.to_s]
39
- rval.is_a?( Hash ) ? Attributes.new( rval ) : rval
27
+ ( ( rval = attributes[name.to_s] ).is_a?( Hash ) and self.new( rval ) ) or rval
40
28
  end
41
29
 
42
- def to_h
43
- @attrs
44
- end
30
+ def to_h ; @attrs ; end
45
31
 
46
32
  alias_method :to_hash, :to_h
47
33
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyoder-filebase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Yoder