Sha256: 48fab597eea011fb700d953beed4917808c1e66ed1ad6b0f1b3c369cfb462044

Contents?: true

Size: 570 Bytes

Versions: 26

Compression:

Stored size: 570 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
  snake = words.map { |word| word.downcase } * '_'
  puts padding + line + ' %<' + snake + '>s'
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ix-cli-0.0.27 bin/ix-tokenize-for-template
ix-cli-0.0.26 bin/ix-tokenize-for-template
ix-cli-0.0.25 bin/ix-tokenize-for-template
ix-cli-0.0.24 bin/ix-tokenize-for-template
ix-cli-0.0.23 bin/ix-tokenize-for-template
ix-cli-0.0.22 bin/ix-tokenize-for-template
ix-cli-0.0.21 bin/ix-tokenize-for-template
ix-cli-0.0.20 bin/ix-tokenize-for-template
ix-cli-0.0.19 bin/ix-tokenize-for-template
ix-cli-0.0.18 bin/ix-tokenize-for-template
ix-cli-0.0.17 bin/ix-tokenize-for-template
ix-cli-0.0.16 bin/ix-tokenize-for-template
ix-cli-0.0.15 bin/ix-tokenize-for-template
ix-cli-0.0.14 bin/ix-tokenize-for-template
ix-cli-0.0.13 bin/ix-tokenize-for-template
ix-cli-0.0.12 bin/ix-tokenize-for-template
ix-cli-0.0.11 bin/ix-tokenize-for-template
ix-cli-0.0.10 bin/ix-tokenize-for-template
ix-cli-0.0.9 bin/ix-tokenize-for-template
ix-cli-0.0.7 bin/ix-tokenize-for-template