Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/activity_notification/helpers/polymorphic_helpers.rb

Instance Method Summary collapse

Instance Method Details

#to_boolean(default = nil) ⇒ Boolean

Convets to boolean. Returns true for ‘true’, ‘1’, ‘yes’, ‘on’ and ‘t’. Returns false for ‘false’, ‘0’, ‘no’, ‘off’ and ‘f’.

Parameters:

  • default (Boolean) (defaults to: nil)

    Default value to return when the String is not interpretable

Returns:

  • (Boolean)

    Convered boolean value



37
38
39
40
41
# File 'lib/activity_notification/helpers/polymorphic_helpers.rb', line 37

def to_boolean(default = nil)
  return true if ['true', '1', 'yes', 'on', 't'].include? self
  return false if ['false', '0', 'no', 'off', 'f'].include? self
  return default
end

#to_model_classClass

Convets to model class.

Returns:

  • (Class)

    Model class



16
17
18
# File 'lib/activity_notification/helpers/polymorphic_helpers.rb', line 16

def to_model_class
  to_model_name.classify.constantize
end

#to_model_nameObject

Convets to model instance.

Returns:

  • (Object)

    Model instance



10
11
12
# File 'lib/activity_notification/helpers/polymorphic_helpers.rb', line 10

def to_model_name
  singularize.camelize
end

#to_resource_nameString

Convets to singularized model name (resource name).

Returns:

  • (String)

    Singularized model name (resource name)



22
23
24
# File 'lib/activity_notification/helpers/polymorphic_helpers.rb', line 22

def to_resource_name
  singularize.underscore
end

#to_resources_nameString

Convets to pluralized model name (resources name).

Returns:

  • (String)

    Pluralized model name (resources name)



28
29
30
# File 'lib/activity_notification/helpers/polymorphic_helpers.rb', line 28

def to_resources_name
  pluralize.underscore
end