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 =
"0.2.0"
Instance Method Summary collapse
-
#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. If extra attributes are sent, a NoMethodError exception will be raised.
37 38 39 40 41 |
# File 'lib/scrivener.rb', line 37 def initialize(atts) atts.each do |key, val| send(:"#{key}=", val) end end |
Instance Method Details
#attributes ⇒ Object
Return hash of attributes and values.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/scrivener.rb', line 44 def attributes Hash.new.tap do |atts| instance_variables.each do |ivar| next if ivar == :@errors att = ivar[1..-1].to_sym atts[att] = send(att) end end end |
#slice(*keys) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/scrivener.rb', line 55 def slice(*keys) Hash.new.tap do |atts| keys.each do |att| atts[att] = send(att) end end end |