Class: MarkdownRubyDocumentation::WriteMarkdownToDisk

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir:, skip_if_blank: false, relative_dir:) ⇒ WriteMarkdownToDisk

Returns a new instance of WriteMarkdownToDisk.



6
7
8
9
10
# File 'lib/markdown_ruby_documentation/write_markdown_to_disk.rb', line 6

def initialize(dir:, skip_if_blank: false, relative_dir:)
  @dir           = dir
  @skip_if_blank = skip_if_blank
  @relative_dir = relative_dir
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



4
5
6
# File 'lib/markdown_ruby_documentation/write_markdown_to_disk.rb', line 4

def dir
  @dir
end

#relative_dirObject (readonly)

Returns the value of attribute relative_dir.



4
5
6
# File 'lib/markdown_ruby_documentation/write_markdown_to_disk.rb', line 4

def relative_dir
  @relative_dir
end

#skip_if_blankObject (readonly)

Returns the value of attribute skip_if_blank.



4
5
6
# File 'lib/markdown_ruby_documentation/write_markdown_to_disk.rb', line 4

def skip_if_blank
  @skip_if_blank
end

Instance Method Details

#call(name:, text:) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/markdown_ruby_documentation/write_markdown_to_disk.rb', line 12

def call(name:, text:)
  return if skip_save?(text, name)
  name = name.gsub(dir, "").underscore
  path = File.join(dir, name)
  FileUtils.mkdir_p(path.split("/").tap { |p| p.pop }.join("/"))
  File.open("#{path}.md", "w").write(text)
end