Class: Sheetah::Messaging::Messenger

Inherits:
Object
  • Object
show all
Defined in:
lib/sheetah/messaging.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope: SCOPES::SHEET, scope_data: nil) ⇒ Messenger

Returns a new instance of Messenger.



70
71
72
73
74
75
76
77
# File 'lib/sheetah/messaging.rb', line 70

def initialize(
  scope: SCOPES::SHEET,
  scope_data: nil
)
  @scope = scope.freeze
  @scope_data = scope_data.freeze
  @messages = []
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



79
80
81
# File 'lib/sheetah/messaging.rb', line 79

def messages
  @messages
end

#scopeObject (readonly)

Returns the value of attribute scope.



79
80
81
# File 'lib/sheetah/messaging.rb', line 79

def scope
  @scope
end

#scope_dataObject (readonly)

Returns the value of attribute scope_data.



79
80
81
# File 'lib/sheetah/messaging.rb', line 79

def scope_data
  @scope_data
end

Instance Method Details

#==(other) ⇒ Object



81
82
83
84
85
86
# File 'lib/sheetah/messaging.rb', line 81

def ==(other)
  other.is_a?(self.class) &&
    scope      == other.scope &&
    scope_data == other.scope_data &&
    messages   == other.messages
end

#dupObject



88
89
90
91
92
93
# File 'lib/sheetah/messaging.rb', line 88

def dup
  self.class.new(
    scope: @scope,
    scope_data: @scope_data
  )
end

#error(code, data = nil) ⇒ Object



150
151
152
# File 'lib/sheetah/messaging.rb', line 150

def error(code, data = nil)
  add(SEVERITIES::ERROR, code, data)
end

#exception(error) ⇒ Object



154
155
156
# File 'lib/sheetah/messaging.rb', line 154

def exception(error)
  error(error.msg_code)
end

#scope_colObject



142
143
144
# File 'lib/sheetah/messaging.rb', line 142

def scope_col(...)
  dup.scope_col!(...)
end

#scope_col!(col, &block) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/sheetah/messaging.rb', line 124

def scope_col!(col, &block)
  scope = case @scope
          when SCOPES::ROW, SCOPES::CELL
            SCOPES::CELL
          else
            SCOPES::COL
          end

  scope_data = @scope_data.dup || {}
  scope_data[:col] = col

  scoping!(scope, scope_data, &block)
end

#scope_rowObject



138
139
140
# File 'lib/sheetah/messaging.rb', line 138

def scope_row(...)
  dup.scope_row!(...)
end

#scope_row!(row, &block) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/sheetah/messaging.rb', line 110

def scope_row!(row, &block)
  scope = case @scope
          when SCOPES::COL, SCOPES::CELL
            SCOPES::CELL
          else
            SCOPES::ROW
          end

  scope_data = @scope_data.dup || {}
  scope_data[:row] = row

  scoping!(scope, scope_data, &block)
end

#scopingObject



106
107
108
# File 'lib/sheetah/messaging.rb', line 106

def scoping(...)
  dup.scoping!(...)
end

#scoping!(scope, scope_data, &block) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/sheetah/messaging.rb', line 95

def scoping!(scope, scope_data, &block)
  scope      = scope.freeze
  scope_data = scope_data.freeze

  if block
    replace_scoping_block(scope, scope_data, &block)
  else
    replace_scoping_noblock(scope, scope_data)
  end
end

#warn(code, data = nil) ⇒ Object



146
147
148
# File 'lib/sheetah/messaging.rb', line 146

def warn(code, data = nil)
  add(SEVERITIES::WARN, code, data)
end