Class: Scrivener
- Inherits:
-
Object
- Object
- Scrivener
- Extended by:
- Types
- Includes:
- Validations
- Defined in:
- lib/scrivener.rb,
lib/scrivener/types.rb,
lib/scrivener/validations.rb
Defined Under Namespace
Modules: Types, Validations
Constant Summary collapse
- VERSION =
"1.0.2"
Constants included from Types
Types::Boolean, Types::Date, Types::DateTime, Types::Decimal, Types::Float, Types::Integer, Types::String, Types::Symbol, Types::Time
Class Method Summary collapse
-
.inherited(sub_class) ⇒ Object
This will allow you to inhreit from other Scrivener classes.
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 Types
Methods included from Validations
Constructor Details
#initialize(atts) ⇒ Scrivener
Initialize with a hash of attributes and values. Extra attributes are discarded.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/scrivener.rb', line 44 def initialize(atts) @_accessors = atts.keys.map { |key| "#{key}=".to_sym } atts.each do |key, val| accessor = "#{key}=" if respond_to?(accessor) send(accessor, val) end end end |
Class Method Details
.inherited(sub_class) ⇒ Object
This will allow you to inhreit from other Scrivener classes
11 12 13 |
# File 'lib/scrivener.rb', line 11 def self.inherited(sub_class) sub_class.send(:attr_accessor, *instance_methods(false).select { |m| !m['='] }) unless self.name == 'Scrivener' end |
Instance Method Details
#_accessors ⇒ Object
56 57 58 59 60 |
# File 'lib/scrivener.rb', line 56 def _accessors @_accessors & public_methods(false).select do |name| name[-1] == "=" end end |
#attributes ⇒ Object
Return hash of attributes and values.
63 64 65 66 67 68 69 70 |
# File 'lib/scrivener.rb', line 63 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
72 73 74 75 76 77 78 |
# File 'lib/scrivener.rb', line 72 def slice(*keys) Hash.new.tap do |atts| keys.each do |att| atts[att] = send(att) end end end |