Skip to content

Commit

Permalink
rubocop -A
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloboyle committed Aug 14, 2024
1 parent b8dff8f commit e3032a0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 26 deletions.
1 change: 1 addition & 0 deletions lib/obsidian_api.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "obsidian_api/version"
require "obsidian_api/vault"
require "obsidian_api/note"
Expand Down
6 changes: 4 additions & 2 deletions lib/obsidian_api/note.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# lib/obsidian_api/note.rb

module ObsidianAPI
Expand Down Expand Up @@ -29,8 +31,8 @@ def add_tag(tag)

def remove_tag(tag)
content = self.content
content.gsub!(/tags:.*\b#{tag}\b,?/, 'tags:')
content.gsub!(/tags:.*\b#{tag}\b,?/, "tags:")
save(content)
end
end
end
end
6 changes: 4 additions & 2 deletions lib/obsidian_api/vault.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# lib/obsidian_api/vault.rb
module ObsidianAPI
class Vault
Expand All @@ -8,7 +10,7 @@ def initialize(path)
end

def list_files
Dir.glob(File.join(@path, '**/*.md'))
Dir.glob(File.join(@path, "**/*.md"))
end

def read(file_path)
Expand All @@ -28,4 +30,4 @@ def delete(file_path)
File.delete(full_path) if File.exist?(full_path)
end
end
end
end
2 changes: 1 addition & 1 deletion obsidian_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ Gem::Specification.new do |spec|

# If you have any specific dependencies, add them here:
# spec.add_dependency "rspec", "~> 3.10" # for testing
end
end
4 changes: 3 additions & 1 deletion spec/obsidian_api_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# spec/obsidian_api_spec.rb

RSpec.describe ObsidianApi do
Expand All @@ -9,4 +11,4 @@
# Replace this with an actual useful test or remove the test
expect(true).to eq(true)
end
end
end
36 changes: 19 additions & 17 deletions spec/vault_spec.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
# frozen_string_literal: true

# spec/vault_spec.rb
require 'obsidian_api/vault'
require "obsidian_api/vault"

RSpec.describe ObsidianAPI::Vault do
let(:vault_path) { 'spec/fixtures/vault' }
let(:vault_path) { "spec/fixtures/vault" }
let(:vault) { ObsidianAPI::Vault.new(vault_path) }

describe '#list_files' do
it 'lists all markdown files in the vault' do
expect(vault.list_files).to include('spec/fixtures/vault/note1.md', 'spec/fixtures/vault/note2.md')
describe "#list_files" do
it "lists all markdown files in the vault" do
expect(vault.list_files).to include("spec/fixtures/vault/note1.md", "spec/fixtures/vault/note2.md")
end
end

describe '#read' do
it 'reads the content of a markdown file' do
content = vault.read('note1.md')
describe "#read" do
it "reads the content of a markdown file" do
content = vault.read("note1.md")
expect(content).to eq("# Note 1\nThis is the first note.")
end
end

describe '#write' do
it 'writes content to a markdown file' do
vault.write('note3.md', "# Note 3\nThis is a new note.")
expect(vault.read('note3.md')).to eq("# Note 3\nThis is a new note.")
describe "#write" do
it "writes content to a markdown file" do
vault.write("note3.md", "# Note 3\nThis is a new note.")
expect(vault.read("note3.md")).to eq("# Note 3\nThis is a new note.")
end
end

describe '#delete' do
it 'deletes a markdown file' do
vault.delete('note3.md')
expect(File.exist?('spec/fixtures/vault/note3.md')).to be false
describe "#delete" do
it "deletes a markdown file" do
vault.delete("note3.md")
expect(File.exist?("spec/fixtures/vault/note3.md")).to be false
end
end
end
end
8 changes: 5 additions & 3 deletions test_vault.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

# test_vault.rb
require 'obsidian_api'
require "obsidian_api"

# Prompt the user for the vault path
puts "Please enter the path to your Obsidian vault:"
Expand Down Expand Up @@ -38,9 +40,9 @@
puts "\nDo you want to delete #{new_note_name}? (y/n)"
delete_confirmation = gets.chomp.downcase

if delete_confirmation == 'y'
if delete_confirmation == "y"
vault.delete(new_note_name)
puts "#{new_note_name} has been deleted."
else
puts "#{new_note_name} has been kept in the vault."
end
end

0 comments on commit e3032a0

Please sign in to comment.