Class: DrHenryPost
- Inherits:
-
Object
- Object
- DrHenryPost
- Defined in:
- lib/drhenrypost.rb
Instance Method Summary collapse
-
#create(date, filename, title) ⇒ Object
Creates the file.
-
#date ⇒ Object
Gets today’s date.
-
#name ⇒ Object
Sets post filename.
-
#title(postName) ⇒ Object
Sets post title (into the file).
Instance Method Details
#create(date, filename, title) ⇒ Object
Creates the file
39 40 41 42 43 44 45 46 |
# File 'lib/drhenrypost.rb', line 39 def create(date, filename, title) output = File.new("#{date}-#{filename}.md", "w") output.puts("---") output.puts("layout: post # Sustituye el layout si lo usas uno diferente") output.puts("title: " + "#{title}" + " # Nombre generado automáticamente") output.puts("---") output.close end |
#date ⇒ Object
Gets today’s date
4 5 6 7 8 |
# File 'lib/drhenrypost.rb', line 4 def date time = Time.new date = time.strftime("%Y-%m-%d") return date.to_s end |
#name ⇒ Object
Sets post filename
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/drhenrypost.rb', line 11 def name string = [] if ARGV.empty? puts "You have not provided a title for the post. Please introduce a title." print "> " STDOUT.flush joinName = gets.chomp nameArray = joinName.split(' ') nameArray.each do |s| string.push(s) end else ARGV.each do |a| string.push(a) end end joinName = string.join('-') return joinName end |
#title(postName) ⇒ Object
Sets post title (into the file)
34 35 36 |
# File 'lib/drhenrypost.rb', line 34 def title(postName) return postName.tr('-', ' ') end |