Class: Scrivener
- Inherits:
-
Object
- Object
- Scrivener
- Includes:
- Validations
- Defined in:
- lib/scrivener.rb,
lib/scrivener/validations.rb
Defined Under Namespace
Modules: Validations
Constant Summary collapse
- VERSION =
"1.1.1"
Instance Method Summary collapse
- #_accessors ⇒ Object
-
#attributes ⇒ Object
Return hash of attributes and values.
-
#initialize(atts) ⇒ Scrivener
constructor
Initialize with a hash of attributes and values.
- #slice(*keys) ⇒ Object
Methods included from Validations
Constructor Details
#initialize(atts) ⇒ Scrivener
Initialize with a hash of attributes and values. Extra attributes are discarded.
37 38 39 40 41 42 43 44 45 |
# File 'lib/scrivener.rb', line 37 def initialize(atts) atts.each do |key, val| accessor = "#{key}=" if respond_to?(accessor) send(accessor, val) end end end |
Instance Method Details
#_accessors ⇒ Object
47 48 49 50 51 |
# File 'lib/scrivener.rb', line 47 def _accessors public_methods(false).select do |name| name[-1] == "=" end end |
#attributes ⇒ Object
Return hash of attributes and values.
54 55 56 57 58 59 60 61 |
# File 'lib/scrivener.rb', line 54 def attributes Hash.new.tap do |atts| _accessors.each do |accessor| att = accessor[0..-2].to_sym atts[att] = send(att) end end end |
#slice(*keys) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/scrivener.rb', line 63 def slice(*keys) Hash.new.tap do |atts| keys.each do |att| atts[att] = send(att) end end end |