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

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

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:

  • context (NilClass) (defaults to: nil)
  • model (NilClass) (defaults to: nil)
  • value (NilClass|String) (defaults to: '')
  • options (Hash) (defaults to: {})
  • block (Proc)
  • 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.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 49

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)


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

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:



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

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:



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

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

#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.



93
94
95
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 93

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)


62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 62

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

#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)


100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 100

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)


210
211
212
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 210

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.



116
117
118
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 116

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>)


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

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)


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

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

#defaultsHash<Symbol => void> (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.

The default options/attributes for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 121

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

#geometryVedeu::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 the named geometry from the geometries repository.



136
137
138
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 136

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

#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)


215
216
217
218
219
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 215

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)


141
142
143
144
145
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 141

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)


222
223
224
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 222

def new_colour_options
  model_colour.merge(coerce_colour_options)
end

#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)


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

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)


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

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

#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:



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

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:



163
164
165
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 163

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

#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>)


168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 168

def value
  if block
    {}

  elsif absent?(@value)
    {}

  else
    {
      value: @value,
    }

  end
end

#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)


184
185
186
187
188
189
190
191
192
# File 'lib/vedeu/dsl/helpers/attributes.rb', line 184

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:



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

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