Class: AaaaAaaa::Text

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

Instance Method Summary collapse

Constructor Details

#initialize(str, step = nil, prefix = "", production: false) ⇒ Text

Returns a new instance of Text.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/aaaa_aaaa.rb', line 9

def initialize(str, step=nil, prefix="", production: false)
  @value = ""
  
  @str = str
  @step = step
  @prefix = prefix
  @production = production
  if @step
    @nextstep = step
  end
end

Instance Method Details

#*(mul) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/aaaa_aaaa.rb', line 49

def *(mul)
  if @step
    @iter = mul / @step
    @iter.times do |x|
      @value += line 
    end
    @value += @str * (mul % @step)
  else
    @value = @str * (mul / @str.length)
  end
  self
end

#lineObject



42
43
44
45
46
47
# File 'lib/aaaa_aaaa.rb', line 42

def line
  step_length = @nextstep.to_s.length - 1
  line_str = prefix_str + (@str * ((@step - (step_length + 1) - (prefix_length)) / @str.length)) + zenkaku_step
  @nextstep += @step
  return line_str
end

#prefix_lengthObject



34
35
36
# File 'lib/aaaa_aaaa.rb', line 34

def prefix_length
  @prefix ? @prefix.length : 0
end

#prefix_strObject



38
39
40
# File 'lib/aaaa_aaaa.rb', line 38

def prefix_str
  @prefix || ""
end

#to_sObject



62
63
64
65
66
67
68
# File 'lib/aaaa_aaaa.rb', line 62

def to_s
  if @production
    raise NotUseAaaaAaaaError, "set procution mode. you must remove AaaaAaaa."
  else
    @value
  end
end

#zenkaku_stepObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/aaaa_aaaa.rb', line 21

def zenkaku_step
  _use_str = @nextstep.to_s
  hankaku_to_zenkaku = 
    [["0", ""], ["1", ""], ["2", ""],
     ["3", ""], ["4", ""], ["5", ""],
     ["6", ""], ["7", ""], ["8", ""],
     ["9", ""]]
  hankaku_to_zenkaku.each do |from, to|
    _use_str.gsub! from, to
  end
  _use_str
end