Sha256: 0e849dfe80414858c2cd455fb1dfea7adf316a1ca3508d243bf8139395b40836

Contents?: true

Size: 533 Bytes

Versions: 19

Compression:

Stored size: 533 Bytes

Contents

#!/usr/bin/env ruby

WORDS_REGEX = /\w+/
UPPER_CASE_WORDS = /([A-Z])/
SPACE_PADDING = /^\s+/
STARTS_WITH_UPPERCASE = /\s*[A-Z]/

starts_with_uppercase = false

STDIN.each_line do |line|
  line.chomp!
  if line =~ STARTS_WITH_UPPERCASE
    starts_with_uppercase = true
  end
  line.gsub!(UPPER_CASE_WORDS, ' \1')
  padding = line.scan(SPACE_PADDING)[0].to_s
  words = line.scan(WORDS_REGEX)

  if starts_with_uppercase
    padding = padding[1..(padding.size - 1)]
  end

  puts padding + words.map { |word| word.downcase } * '_'
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ix-cli-0.0.20 bin/ix-snake
ix-cli-0.0.19 bin/ix-snake
ix-cli-0.0.18 bin/ix-snake
ix-cli-0.0.17 bin/ix-snake
ix-cli-0.0.16 bin/ix-snake
ix-cli-0.0.15 bin/ix-snake
ix-cli-0.0.14 bin/ix-snake
ix-cli-0.0.13 bin/ix-snake
ix-cli-0.0.12 bin/ix-snake
ix-cli-0.0.11 bin/ix-snake
ix-cli-0.0.10 bin/ix-snake
ix-cli-0.0.9 bin/ix-snake
ix-cli-0.0.7 bin/ix-snake
ix-cli-0.0.6 bin/ix-snake
ix-cli-0.0.5 bin/ix-snake
ix-cli-0.0.4 bin/ix-snake
ix-cli-0.0.3 bin/ix-snake
ix-cli-0.0.2 bin/ix-snake
ix-cli-0.0.1 bin/ix-snake