Class: Vedeu::DSL::Attributes Private

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/vedeu/dsl/helpers/attributes.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Creates attributes for DSL objects.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context = nil, model = nil, value = '', options = {}, &block) ⇒ Vedeu::DSL::Attributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • options (Hash) (defaults to: {})
  • colour (Hash)

    a customizable set of options

Options Hash (options):

  • align (Symbol)

    One of :center, :centre, :left, :none (default) or :right.

  • background (String)

    The background colour.

  • colour (Hash)

    The colour.

  • foreground (String)

    The foreground colour.

  • name (NilClass|String|Symbol)
  • pad (String)

    The character to use to pad the value.

  • style (Array<Symbol>| Hash<Symbol => Array<Symbol>|Symbol>|Symbol)

    The style.

  • truncate (Boolean)

    Whether the value should be truncated.

  • width (Fixnum)

    The desired width for the value.

  • wordwrap (Boolean)

    Whether the value should be wordwrapped.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 45

def initialize(context = nil,
               model   = nil,
               value   = '',
               options = {},
               &block)
  @context = context
  @model   = model
  @value   = value   || ''
  @options = options || {}
  @block   = block
end

Instance Attribute Details

#blockNilClass|Proc (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (NilClass|Proc)


84
85
86
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 84

def block
  @block
end

#contextNilClass|Vedeu::DSL::Elements (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



76
77
78
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 76

def context
  @context
end

#modelNilClass|Vedeu::Views::* (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



80
81
82
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 80

def model
  @model
end

Class Method Details

.build(context = nil, model = nil, value = '', options = {}, &block) ⇒ Hash<Symbol => void>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • model (void) (defaults to: nil)

    The model class which the DSL class is wrapping.

  • client (void)

    The class where the DSL methods are being used.

Returns:

  • (Hash<Symbol => void>)


17
18
19
20
21
22
23
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 17

def self.build(context = nil,
               model   = nil,
               value   = '',
               options = {},
               &block)
  new(context, model, value, options, &block).attributes
end

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#alignVedeu::Coercers::Alignment (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



89
90
91
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 89

def align
  Vedeu::Coercers::Alignment.coerce(options[:align])
end

#attributesHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 58

def attributes
  {
    align:    align,
    client:   client,
    colour:   colour,
    name:     name,
    pad:      pad,
    style:    style,
    truncate: truncate,
    width:    width,
    wordwrap: wordwrap,
  }.merge!(value)
end

#become(klass, attributes) ⇒ Class Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

#boolean(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the value was a boolean.

Parameters:

  • value (void)

Returns:

#boolean?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Boolean.

Parameters:

Returns:

#clientObject (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the client object which called the DSL method.

Returns:

  • (Object)


96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 96

def client
  if block
    if eval('client', block.binding).nil?
      eval(context.class.name, block.binding)

    else
      eval('client', block.binding)

    end
  elsif present?(model)
    model.client

  end
end

#coerce_colour_optionsHash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


206
207
208
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 206

def coerce_colour_options
  Vedeu::Coercers::ColourAttributes.coerce(colour_options)
end

#colourVedeu::Colours::Colour (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



112
113
114
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 112

def colour
  Vedeu::Colours::Colour.coerce(new_colour_options)
end

#colour_attributesArray<Symbol> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<Symbol>)


196
197
198
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 196

def colour_attributes
  [:background, :colour, :foreground]
end

#colour_optionsHash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


201
202
203
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 201

def colour_options
  options.select { |k, _| colour_attributes.include?(k) }
end

#defaultsHash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 117

def defaults
  {
    align:      :none,
    client:     nil,
    colour:     nil,
    name:       nil,
    pad:        ' ',
    style:      nil,
    truncate:   false,
    width:      nil,
    wordwrap:   false,
  }
end

#escape?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

#falsy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered false.

Parameters:

  • value (void)

Returns:

#geometryNilClass|Vedeu::Geometries::Geometry (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



132
133
134
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 132

def geometry
  @_geometry ||= Vedeu.geometries.by_name(name)
end

#hash?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

#line_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Line.

Returns:

#model_colourHash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


211
212
213
214
215
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 211

def model_colour
  return {} unless present?(model) && model.colour

  model.colour.attributes
end

#nameNilClass|String|Symbol (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (NilClass|String|Symbol)


137
138
139
140
141
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 137

def name
  return model.name if present?(model) && present?(model.name)

  nil
end

#new_colour_optionsHash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


218
219
220
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 218

def new_colour_options
  model_colour.merge(coerce_colour_options)
end

#numeric?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

#optionsHash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


144
145
146
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 144

def options
  defaults.merge!(@options)
end

#padString (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


149
150
151
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 149

def pad
  options[:pad].to_s[0] || ' '
end

#present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#snake_case(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

snake_case('MyClassName') # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

#stream_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Stream.

Returns:

#string?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

#styleNilClass|Vedeu::Presentation::Style (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



154
155
156
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 154

def style
  Vedeu::Presentation::Style.coerce(options[:style])
end

#truncateBoolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



159
160
161
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 159

def truncate
  truthy?(options[:truncate])
end

#truthy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered true.

Parameters:

  • value (void)

Returns:

#valueHash<Symbol => String> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol => String>)


164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 164

def value
  if block
    {}

  elsif absent?(@value)
    {}

  else
    {
      value: @value,
    }

  end
end

#view_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::View.

Returns:

#widthFixnum|NilClass (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum|NilClass)


180
181
182
183
184
185
186
187
188
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 180

def width
  if numeric?(options[:width])
    options[:width]

  elsif view_model? && name
    geometry.bordered_width

  end
end

#wordwrapBoolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



191
192
193
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 191

def wordwrap
  truthy?(options[:wordwrap])
end