Module: TwistyPuzzles::Utils::StringHelper

Included in:
AbstractMove, PartCycle, PartCycle
Defined in:
lib/twisty_puzzles/utils/string_helper.rb

Overview

A few string related helper methods.

Instance Method Summary collapse

Instance Method Details

#camel_case_to_snake_case(camel_case) ⇒ Object



7
8
9
10
11
# File 'lib/twisty_puzzles/utils/string_helper.rb', line 7

def camel_case_to_snake_case(camel_case)
  camel_case.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
            .gsub(/([a-z\d])([A-Z])/, '\1_\2')
            .downcase
end

#format_time(time_s) ⇒ Object



21
22
23
# File 'lib/twisty_puzzles/utils/string_helper.rb', line 21

def format_time(time_s)
  format('%<time_s>.2f', time_s: time_s)
end

#simple_class_name(clazz) ⇒ Object



13
14
15
# File 'lib/twisty_puzzles/utils/string_helper.rb', line 13

def simple_class_name(clazz)
  clazz.name.split('::').last
end

#snake_case_class_name(clazz) ⇒ Object



17
18
19
# File 'lib/twisty_puzzles/utils/string_helper.rb', line 17

def snake_case_class_name(clazz)
  camel_case_to_snake_case(simple_class_name(clazz))
end