Class: Signnow::Base

Inherits:
Object
  • Object
show all
Includes:
Operations::All, Operations::Create, Operations::Find
Defined in:
lib/signnow/base.rb

Direct Known Subclasses

Document, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Operations::Find

included

Methods included from Operations::Create

included

Methods included from Operations::All

included

Constructor Details

#initialize(attributes = {}) ⇒ Base

Initializes the object using the given attributes

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes to use for initialization



12
13
14
15
# File 'lib/signnow/base.rb', line 12

def initialize(attributes = {})
  set_attributes(attributes)
  parse_timestamps
end

Instance Attribute Details

#createdObject

Returns the value of attribute created.



7
8
9
# File 'lib/signnow/base.rb', line 7

def created
  @created
end

Instance Method Details

#errorsObject

Accesor for the errors



26
27
28
# File 'lib/signnow/base.rb', line 26

def errors
  @errors || []
end

#parse_timestampsObject

Parses UNIX timestamps and creates Time objects.



40
41
42
43
# File 'lib/signnow/base.rb', line 40

def parse_timestamps
  @created = created.to_i if created.is_a? String
  @created = Time.at(created) if created
end

#set_attributes(attributes) ⇒ Object

Sets the attributes

Parameters:

  • attributes (Hash)

    The attributes to initialize



33
34
35
36
37
# File 'lib/signnow/base.rb', line 33

def set_attributes(attributes)
  attributes.each_pair do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

#valid?Boolean

Model validations

Returns:

  • (Boolean)


20
21
22
# File 'lib/signnow/base.rb', line 20

def valid?
  self.errors.empty?
end